Class ProtobufRecord
- java.lang.Object
-
- org.openstreetmap.josm.data.protobuf.ProtobufRecord
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public class ProtobufRecord extends java.lang.Object implements java.lang.AutoCloseable
A protobuf record, storing theWireType, the parsed field number, and the bytes for it.- Since:
- 17862
-
-
Field Summary
Fields Modifier and Type Field Description private byte[]bytesprivate static byte[]EMPTY_BYTESprivate intfieldprivate WireTypetype
-
Constructor Summary
Constructors Constructor Description ProtobufRecord(java.io.ByteArrayOutputStream byteArrayOutputStream, ProtobufParser parser)Create a new Protobuf record
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description doubleasDouble()Get as a double (WireType.SIXTY_FOUR_BIT)byte[]asFixed32()Get as 32 bits (WireType.THIRTY_TWO_BIT)byte[]asFixed64()Get as 64 bits (WireType.SIXTY_FOUR_BIT)floatasFloat()Get as a float (WireType.THIRTY_TWO_BIT)java.lang.NumberasSignedVarInt()Get the signed var int (WireType#VARINT).java.lang.StringasString()Get as a string (WireType.LENGTH_DELIMITED)java.lang.NumberasUnsignedVarInt()Get the var int (WireType#VARINT)voidclose()byte[]getBytes()Get the raw bytes for this recordintgetField()Get the field valueWireTypegetType()Get the WireType of the data
-
-
-
Field Detail
-
EMPTY_BYTES
private static final byte[] EMPTY_BYTES
-
field
private final int field
-
bytes
private byte[] bytes
-
-
Constructor Detail
-
ProtobufRecord
public ProtobufRecord(java.io.ByteArrayOutputStream byteArrayOutputStream, ProtobufParser parser) throws java.io.IOException
Create a new Protobuf record- Parameters:
byteArrayOutputStream- A reusable ByteArrayOutputStream to avoid unnecessary allocationsparser- The parser to use to create the record- Throws:
java.io.IOException- - if an IO error occurs
-
-
Method Detail
-
asDouble
public double asDouble()
Get as a double (WireType.SIXTY_FOUR_BIT)- Returns:
- the double
-
asFixed32
public byte[] asFixed32()
Get as 32 bits (WireType.THIRTY_TWO_BIT)- Returns:
- a byte array of the 32 bits (4 bytes)
-
asFixed64
public byte[] asFixed64()
Get as 64 bits (WireType.SIXTY_FOUR_BIT)- Returns:
- a byte array of the 64 bits (8 bytes)
-
asFloat
public float asFloat()
Get as a float (WireType.THIRTY_TWO_BIT)- Returns:
- the float
-
asSignedVarInt
public java.lang.Number asSignedVarInt()
Get the signed var int (WireType#VARINT). These are specially encoded so that they take up less space.- Returns:
- The signed var int (
sint32orsint64)
-
asString
public java.lang.String asString()
Get as a string (WireType.LENGTH_DELIMITED)- Returns:
- The string (encoded as
StandardCharsets.UTF_8)
-
asUnsignedVarInt
public java.lang.Number asUnsignedVarInt()
Get the var int (WireType#VARINT)- Returns:
- The var int (
int32,int64,uint32,uint64,bool,enum)
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable
-
getBytes
public byte[] getBytes()
Get the raw bytes for this record- Returns:
- The bytes
-
getField
public int getField()
Get the field value- Returns:
- The field value
-
-