Read a single byte for field type, then read the value.
193429
def _read_field(self):
        '''
        
        '''
        ftype = self._input[self._pos]
        self._pos += 1

        reader = self.field_type_map.get(ftype)
        if reader:
            return reader(self)

        raise Reader.FieldError('Unknown field type %s', ftype)
361027
def _read_group_field(self, group, levels, field_type, field_size,  
                          decrypted_content):
        """"""

        if field_type == 0x0000:
            # Ignored (commentar block)
            pass
        elif field_type == 0x0001:
            group.id_ = struct.unpack('<I', decrypted_content[:4])[0]
        elif field_type == 0x0002:
            try:
                group.title = struct.unpack('<{0}s'.format(field_size-1),
                    decrypted_content[:field_size-1])[0].decode('utf-8')
            except UnicodeDecodeError:
                group.title = struct.unpack('<{0}s'.format(field_size-1),
                    decrypted_content[:field_size-1])[0].decode('latin-1')
            decrypted_content = decrypted_content[1:]
        elif field_type == 0x0003:
            group.creation = self._get_date(decrypted_content)
        elif field_type == 0x0004:
            group.last_mod = self._get_date(decrypted_content)
        elif field_type == 0x0005:
            group.last_access = self._get_date(decrypted_content)
        elif field_type == 0x0006:
            group.expire = self._get_date(decrypted_content)
        elif field_type == 0x0007:
            group.image = struct.unpack('<I', decrypted_content[:4])[0]
        elif field_type == 0x0008:
            level = struct.unpack('<H', decrypted_content[:2])[0]
            group.level = level
            levels.append(level)
        elif field_type == 0x0009:
            group.flags = struct.unpack('<I', decrypted_content[:4])[0]
        elif field_type == 0xFFFF:
            pass
        else:
            return False
        return True
1299191
def read(self, num_bytes=None):
        """"""
        res = self.get_next(num_bytes)
        self.skip(len(res))
        return res
741144
def Field(self, field, Value = None):
        '''
        
        '''
        if Value == None:
            try:
                return self.__Bitmap[field]
            except KeyError:
                return None
        elif Value == 1 or Value == 0:
            self.__Bitmap[field] = Value
        else:
            raise ValueError
1052598
public static Byte readByte(String value, Byte defaultValue) {
		if (!StringUtils.hasText(value)) return defaultValue;
		
		return Byte.valueOf(value);
	}
589083
public String readType()
        throws IOException
    {
        int code = read();

        if (code != 't') {
            _peek = code;
            return "";
        }

        _isLastChunk = true;
        _chunkLength = (read() << 8) + read();

        _sbuf.setLength(0);
        int ch;
        while ((ch = parseChar()) >= 0)
            _sbuf.append((char) ch);

        return _sbuf.toString();
    }
201662
static private int readBytes(int c[], int len, InputStream is)
                throws IOException {

        byte buf[] = new byte[len];
        if (is.read(buf, 0, len) < len) {
            return -1;
        }

        // fill the passed in int array
        for (int i = 0; i < len; i++) {
             c[i] = buf[i] & 0xff;
        }
        return 0;
    }
702840
def _bytes_from_json(value, field):
    """"""
    if _not_null(value, field):
        return base64.standard_b64decode(_to_bytes(value))
460559
private Object readKey(
          FieldDescriptor field,
          JsonParser parser,
          DeserializationContext context
  ) throws IOException {
    if (parser.getCurrentToken() != JsonToken.FIELD_NAME) {
      throw reportWrongToken(JsonToken.FIELD_NAME, context, "Expected FIELD_NAME token");
    }

    String fieldName = parser.getCurrentName();
    switch (field.getJavaType()) {
      case INT:
        // lifted from StdDeserializer since there's no method to call
        try {
          return NumberInput.parseInt(fieldName.trim());
        } catch (IllegalArgumentException iae) {
          Number number = (Number) context.handleWeirdStringValue(
                  _valueClass,
                  fieldName.trim(),
                  "not a valid int value"
          );
          return number == null ? 0 : number.intValue();
        }
      case LONG:
        // lifted from StdDeserializer since there's no method to call
        try {
          return NumberInput.parseLong(fieldName.trim());
        } catch (IllegalArgumentException iae) {
          Number number = (Number) context.handleWeirdStringValue(
                  _valueClass,
                  fieldName.trim(),
                  "not a valid long value"
          );
          return number == null ? 0L : number.longValue();
        }
      case BOOLEAN:
        // lifted from StdDeserializer since there's no method to call
        String text = fieldName.trim();
        if ("true".equals(text) || "True".equals(text)) {
          return true;
        }
        if ("false".equals(text) || "False".equals(text)) {
          return false;
        }
        Boolean b = (Boolean) context.handleWeirdStringValue(
                _valueClass,
                text,
                "only \"true\" or \"false\" recognized"
        );
        return Boolean.TRUE.equals(b);
      case STRING:
        return fieldName;
      case ENUM:
        EnumValueDescriptor enumValueDescriptor = field.getEnumType().findValueByName(parser.getText());

        if (enumValueDescriptor == null && !ignorableEnum(parser.getText().trim(), context)) {
          throw context.weirdStringException(parser.getText(), field.getEnumType().getClass(),
                  "value not one of declared Enum instance names");
        }

        return enumValueDescriptor;
      default:
        throw new IllegalArgumentException("Unexpected map key type: " + field.getJavaType());
    }
  }
796537
private Map<Short, LocalVariableDefinition> readSingleFieldValue(MethodDefinition read)
    {
        LocalVariableDefinition protocol = read.getLocalVariable("reader");

        // declare and init local variables here
        Map<Short, LocalVariableDefinition> unionData = new TreeMap<>();
        for (ThriftFieldMetadata field : metadata.getFields(THRIFT_FIELD)) {
            LocalVariableDefinition variable = read.addInitializedLocalVariable(
                    toParameterizedType(field.getThriftType()),
                    "f_" + field.getName()
            );
            unionData.put(field.getId(), variable);
        }

        // protocol.readStructBegin();
        read.loadVariable(protocol).invokeVirtual(
                TProtocolReader.class,
                "readStructBegin",
                void.class
        );

        // while (protocol.nextField())
        read.visitLabel("while-begin");
        read.loadVariable(protocol).invokeVirtual(TProtocolReader.class, "nextField", boolean.class);
        read.ifZeroGoto("while-end");

        // fieldId = protocol.getFieldId()
        read.loadVariable(protocol).invokeVirtual(TProtocolReader.class, "getFieldId", short.class);
        read.storeVariable("fieldId");

        // switch (fieldId)
        read.loadVariable("fieldId");

        List<CaseStatement> cases = new ArrayList<>();
        for (ThriftFieldMetadata field : metadata.getFields(THRIFT_FIELD)) {
            cases.add(caseStatement(field.getId(), field.getName() + "-field"));
        }
        read.switchStatement("default", cases);

        for (ThriftFieldMetadata field : metadata.getFields(THRIFT_FIELD)) {
            // case field.id:
            read.visitLabel(field.getName() + "-field");

            // push protocol
            read.loadVariable(protocol);

            // push ThriftTypeCodec for this field
            FieldDefinition codecField = codecFields.get(field.getId());
            if (codecField != null) {
                read.loadThis().getField(codecType, codecField);
            }

            // read value
            Method readMethod = getReadMethod(field.getThriftType());
            if (readMethod == null) {
                throw new IllegalArgumentException("Unsupported field type " + field.getThriftType().getProtocolType());
            }
            read.invokeVirtual(readMethod);

            // todo this cast should be based on readMethod return type and fieldType (or coercion type)
            // add cast if necessary
            if (needsCastAfterRead(field, readMethod)) {
                read.checkCast(toParameterizedType(field.getThriftType()));
            }

            // coerce the type
            if (field.getCoercion().isPresent()) {
                read.invokeStatic(field.getCoercion().get().getFromThrift());
            }

            // store protocol value
            read.storeVariable(unionData.get(field.getId()));

            // go back to top of loop
            read.gotoLabel("while-begin");
        }

        // default case
        read.visitLabel("default")
                .loadVariable(protocol)
                .invokeVirtual(TProtocolReader.class, "skipFieldData", void.class)
                .gotoLabel("while-begin");

        // end of while loop
        read.visitLabel("while-end");

        // protocol.readStructEnd();
        read.loadVariable(protocol)
                .invokeVirtual(TProtocolReader.class, "readStructEnd", void.class);

        return unionData;
    }
1356548
def _convert_to_bytes(type_name, value):
    """"""

    int_types = {'uint8_t': 'B', 'int8_t': 'b', 'uint16_t': 'H', 'int16_t': 'h', 'uint32_t': 'L', 'int32_t': 'l'}

    type_name = type_name.lower()

    if type_name not in int_types and type_name not in ['string', 'binary']:
        raise ArgumentError('Type must be a known integer type, integer type array, string', known_integers=int_types.keys(), actual_type=type_name)

    if type_name == 'string':
        #value should be passed as a string
        bytevalue = bytes(value)
    elif type_name == 'binary':
        bytevalue = bytes(value)
    else:
        bytevalue = struct.pack("<%s" % int_types[type_name], value)

    return bytevalue
386268
def read_uint(data, start, length):
    """"""
    return int.from_bytes(data[start:start+length], byteorder='big')
59463
def to_bytes(value):
    
    vtype = type(value)

    if vtype == bytes or vtype == type(None):
        return value

    try:
        return vtype.encode(value)
    except UnicodeEncodeError:
        pass
    return value
197254
public int read(byte []buf, int offset, int length) throws IOException
  {
    try {
      return readInt(buf, offset, length);
    } catch (IOException e) {
      _isKeepalive = false;
      throw e;
    } catch (RuntimeException e) {
      _isKeepalive = false;
      throw e;
    }
  }
1366868
private Object readValue(Type t) throws IOException {
		switch (t) {
		case START_OBJECT:
			return parseObjectInternal();
		
		case START_ARRAY:
			return parseArrayInternal();
		
		case STRING:
			return lexer.readString();
		
		case NUMBER:
			return lexer.readNumber();
		
		case TRUE:
			return true;
		
		case FALSE:
			return false;
		
		case NULL:
			return null;
			
		default:
			throw new IOException("Unexpected token: " + t);
		}
	}
780524
def parse_bytes(field):
    '''
    
    '''
    if field[-1] in 'bB':
        field = field[:-1]

    try:
        for i, prefix in enumerate('KMGTPEZ'):
            if field.endswith(prefix + 'i'):
                factor = 2 ** (10 * (i + 1))
                return float(field[:-2]) * factor

        return float(field)
    except ValueError:
        return None
908872
def read_bytes(fo, writer_schema=None, reader_schema=None):
    """"""
    size = read_long(fo)
    return fo.read(size)