@Override public int getMaxSerializedSize() { int size = 4 * values.size(); // max 4 bytes for storing each value's size for (Value v : values) { size += ValueUtility.toGbp(v).getSerializedSize(); } return size; }
/** Encode using regular protobuf delimited field writes */ @Override public void writeTo(ByteBuffer bb) { VarIntUtil.writeVarInt32(bb, values.size()); for (Value v : values) { byte[] b = ValueUtility.toGbp(v).toByteArray(); VarIntUtil.writeVarInt32(bb, b.length); bb.put(b); } }
@Override public void updatedCommand(CommandId cmdId, long changeDate, String key, Value value) { CommandHistoryAttribute cha = CommandHistoryAttribute.newBuilder() .setName(key) .setValue(ValueUtility.toGbp(value)) .build(); CommandHistoryEntry entry = CommandHistoryEntry.newBuilder().setCommandId(cmdId).addAttr(cha).build(); doSend(entry); }
/** Decode using regular protobuf delimited field writes */ private void parse(ByteBuffer bb) throws DecodingException { int num = VarIntUtil.readVarInt32(bb); for (int i = 0; i < num; i++) { int size = VarIntUtil.readVarInt32(bb); byte[] b = new byte[size]; bb.get(b); try { Value v = ValueUtility.fromGpb(org.yamcs.protobuf.Yamcs.Value.parseFrom(b)); values.add(v); } catch (InvalidProtocolBufferException e) { throw new DecodingException("Failed to decode Value: ", e); } } }