MCPcopy Create free account
hub / github.com/Whiley/WhileyCompiler / writeData

Method writeData

src/main/java/wycc/io/HeapWriter.java:107–132  ·  view source on GitHub ↗
(Item item)

Source from the content-addressed store, hash-verified

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

Callers 1

writeSyntacticItemMethod · 0.95

Calls 6

getDataLayoutMethod · 0.80
write_uvMethod · 0.80
write_u8Method · 0.80
getDescriptorMethod · 0.65
getOpcodeMethod · 0.65
getDataMethod · 0.65

Tested by

no test coverage detected