| 27 | import packetproxy.quic.value.VariableLengthInteger; |
| 28 | |
| 29 | @Value |
| 30 | public class DataFrame implements Frame { |
| 31 | |
| 32 | public static final long TYPE = 0x00; |
| 33 | |
| 34 | public static List<Long> supportedTypes() { |
| 35 | return ImmutableList.of(TYPE); |
| 36 | } |
| 37 | |
| 38 | public static DataFrame parse(ByteBuffer buffer) { |
| 39 | long frameType = VariableLengthInteger.parse(buffer).getValue(); |
| 40 | long frameLength = VariableLengthInteger.parse(buffer).getValue(); |
| 41 | byte[] frameData = SimpleBytes.parse(buffer, frameLength).getBytes(); |
| 42 | return new DataFrame(frameData); |
| 43 | } |
| 44 | |
| 45 | public static DataFrame of(byte[] frameData) { |
| 46 | return new DataFrame(frameData); |
| 47 | } |
| 48 | |
| 49 | long type; |
| 50 | byte[] data; |
| 51 | |
| 52 | private DataFrame(byte[] frameData) { |
| 53 | this.type = TYPE; |
| 54 | this.data = frameData; |
| 55 | } |
| 56 | |
| 57 | public byte[] getData() { |
| 58 | return this.data; |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public byte[] getBytes() { |
| 63 | ByteArrayOutputStream frameStream = new ByteArrayOutputStream(); |
| 64 | try { |
| 65 | |
| 66 | frameStream.write(VariableLengthInteger.of(this.type).getBytes()); |
| 67 | frameStream.write(VariableLengthInteger.of(this.data.length).getBytes()); |
| 68 | frameStream.write(this.data); |
| 69 | } catch (Exception e) { |
| 70 | |
| 71 | errWithStackTrace(e); |
| 72 | } |
| 73 | return frameStream.toByteArray(); |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public String toString() { |
| 78 | return String.format("DataFrame(data=[%s])", Hex.encodeHexString(this.data)); |
| 79 | } |
| 80 | } |
nothing calls this directly
no outgoing calls
no test coverage detected