(Item item)
| 105 | } |
| 106 | |
| 107 | public void writeData(Item item) throws IOException { |
| 108 | // Determine data layout |
| 109 | Item.Data layout = schema.getDescriptor(item.getOpcode()).getDataLayout(); |
| 110 | byte[] bytes = item.getData(); |
| 111 | // Write data according to layout |
| 112 | switch (layout) { |
| 113 | case MANY: |
| 114 | out.write_uv(bytes.length); |
| 115 | break; |
| 116 | default: |
| 117 | if(bytes != null && layout.ordinal() != bytes.length) { |
| 118 | throw new IllegalArgumentException( |
| 119 | "invalid number of data bytes for " + item.getClass().getSimpleName() + " (got " + bytes.length |
| 120 | + ", expecting " + layout.ordinal() + ")"); |
| 121 | } else if(bytes == null && layout.ordinal() != 0) { |
| 122 | throw new IllegalArgumentException( |
| 123 | "invalid number of data bytes for " + item.getClass().getSimpleName() + " (got none, expecting " |
| 124 | + layout.ordinal() + ")"); |
| 125 | } |
| 126 | } |
| 127 | if(bytes != null) { |
| 128 | for (int i = 0; i != bytes.length; ++i) { |
| 129 | out.write_u8(bytes[i]); |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | public static final Map<Integer,Metric> metrics = new HashMap<>(); |
| 135 |
no test coverage detected