public int compareTo(MetadataComponent o) { return this.getType().compareTo(o.getType()); } }
public void serialize(Map<MetadataType, MetadataComponent> components, DataOutputPlus out, Version version) throws IOException { // sort components by type List<MetadataComponent> sortedComponents = Lists.newArrayList(components.values()); Collections.sort(sortedComponents); // write number of component out.writeInt(components.size()); // build and write toc int lastPosition = 4 + (8 * sortedComponents.size()); for (MetadataComponent component : sortedComponents) { MetadataType type = component.getType(); // serialize type out.writeInt(type.ordinal()); // serialize position out.writeInt(lastPosition); lastPosition += type.serializer.serializedSize(version, component); } // serialize components for (MetadataComponent component : sortedComponents) { component.getType().serializer.serialize(version, component, out); } }
public Map<MetadataType, MetadataComponent> deserialize(Descriptor descriptor, FileDataInput in, EnumSet<MetadataType> types) throws IOException { Map<MetadataType, MetadataComponent> components = new EnumMap<>(MetadataType.class); // read number of components int numComponents = in.readInt(); // read toc Map<MetadataType, Integer> toc = new EnumMap<>(MetadataType.class); MetadataType[] values = MetadataType.values(); for (int i = 0; i < numComponents; i++) { toc.put(values[in.readInt()], in.readInt()); } for (MetadataType type : types) { Integer offset = toc.get(type); if (offset != null) { in.seek(offset); MetadataComponent component = type.serializer.deserialize(descriptor.version, in); components.put(type, component); } } return components; }
public void serialize(Map<MetadataType, MetadataComponent> components, DataOutputPlus out, Version version) throws IOException { // sort components by type List<MetadataComponent> sortedComponents = Lists.newArrayList(components.values()); Collections.sort(sortedComponents); // write number of component out.writeInt(components.size()); // build and write toc int lastPosition = 4 + (8 * sortedComponents.size()); for (MetadataComponent component : sortedComponents) { MetadataType type = component.getType(); // serialize type out.writeInt(type.ordinal()); // serialize position out.writeInt(lastPosition); lastPosition += type.serializer.serializedSize(version, component); } // serialize components for (MetadataComponent component : sortedComponents) { component.getType().serializer.serialize(version, component, out); } }
public Map<MetadataType, MetadataComponent> deserialize(Descriptor descriptor, FileDataInput in, EnumSet<MetadataType> types) throws IOException { Map<MetadataType, MetadataComponent> components = new EnumMap<>(MetadataType.class); // read number of components int numComponents = in.readInt(); // read toc Map<MetadataType, Integer> toc = new EnumMap<>(MetadataType.class); MetadataType[] values = MetadataType.values(); for (int i = 0; i < numComponents; i++) { toc.put(values[in.readInt()], in.readInt()); } for (MetadataType type : types) { Integer offset = toc.get(type); if (offset != null) { in.seek(offset); MetadataComponent component = type.serializer.deserialize(descriptor.version, in); components.put(type, component); } } return components; }
public int compareTo(MetadataComponent o) { return this.getType().compareTo(o.getType()); } }
public void serialize(Map<MetadataType, MetadataComponent> components, DataOutputPlus out, Version version) throws IOException { // sort components by type List<MetadataComponent> sortedComponents = Lists.newArrayList(components.values()); Collections.sort(sortedComponents); // write number of component out.writeInt(components.size()); // build and write toc int lastPosition = 4 + (8 * sortedComponents.size()); for (MetadataComponent component : sortedComponents) { MetadataType type = component.getType(); // serialize type out.writeInt(type.ordinal()); // serialize position out.writeInt(lastPosition); lastPosition += type.serializer.serializedSize(version, component); } // serialize components for (MetadataComponent component : sortedComponents) { component.getType().serializer.serialize(version, component, out); } }
public Map<MetadataType, MetadataComponent> deserialize(Descriptor descriptor, FileDataInput in, EnumSet<MetadataType> types) throws IOException { Map<MetadataType, MetadataComponent> components = new EnumMap<>(MetadataType.class); // read number of components int numComponents = in.readInt(); // read toc Map<MetadataType, Integer> toc = new EnumMap<>(MetadataType.class); MetadataType[] values = MetadataType.values(); for (int i = 0; i < numComponents; i++) { toc.put(values[in.readInt()], in.readInt()); } for (MetadataType type : types) { Integer offset = toc.get(type); if (offset != null) { in.seek(offset); MetadataComponent component = type.serializer.deserialize(descriptor.version, in); components.put(type, component); } } return components; }
public int compareTo(MetadataComponent o) { return this.getType().compareTo(o.getType()); } }
public void serialize(Map<MetadataType, MetadataComponent> components, DataOutputPlus out, Version version) throws IOException { // sort components by type List<MetadataComponent> sortedComponents = Lists.newArrayList(components.values()); Collections.sort(sortedComponents); // write number of component out.writeInt(components.size()); // build and write toc int lastPosition = 4 + (8 * sortedComponents.size()); for (MetadataComponent component : sortedComponents) { MetadataType type = component.getType(); // serialize type out.writeInt(type.ordinal()); // serialize position out.writeInt(lastPosition); lastPosition += type.serializer.serializedSize(version, component); } // serialize components for (MetadataComponent component : sortedComponents) { component.getType().serializer.serialize(version, component, out); } }
public Map<MetadataType, MetadataComponent> deserialize(Descriptor descriptor, FileDataInput in, EnumSet<MetadataType> types) throws IOException { Map<MetadataType, MetadataComponent> components = new EnumMap<>(MetadataType.class); // read number of components int numComponents = in.readInt(); // read toc Map<MetadataType, Integer> toc = new EnumMap<>(MetadataType.class); MetadataType[] values = MetadataType.values(); for (int i = 0; i < numComponents; i++) { toc.put(values[in.readInt()], in.readInt()); } for (MetadataType type : types) { Integer offset = toc.get(type); if (offset != null) { in.seek(offset); MetadataComponent component = type.serializer.deserialize(descriptor.version, in); components.put(type, component); } } return components; }
public int compareTo(MetadataComponent o) { return this.getType().compareTo(o.getType()); } }
public void serialize(Map<MetadataType, MetadataComponent> components, DataOutputPlus out) throws IOException { // sort components by type List<MetadataComponent> sortedComponents = Lists.newArrayList(components.values()); Collections.sort(sortedComponents); // write number of component out.writeInt(components.size()); // build and write toc int lastPosition = 4 + (8 * sortedComponents.size()); for (MetadataComponent component : sortedComponents) { MetadataType type = component.getType(); // serialize type out.writeInt(type.ordinal()); // serialize position out.writeInt(lastPosition); lastPosition += type.serializer.serializedSize(component); } // serialize components for (MetadataComponent component : sortedComponents) { component.getType().serializer.serialize(component, out); } }
public Map<MetadataType, MetadataComponent> deserialize(Descriptor descriptor, FileDataInput in, EnumSet<MetadataType> types) throws IOException { Map<MetadataType, MetadataComponent> components = Maps.newHashMap(); // read number of components int numComponents = in.readInt(); // read toc Map<MetadataType, Integer> toc = new HashMap<>(numComponents); for (int i = 0; i < numComponents; i++) { toc.put(MetadataType.values()[in.readInt()], in.readInt()); } for (MetadataType type : types) { MetadataComponent component = null; if (toc.containsKey(type)) { in.seek(toc.get(type)); component = type.serializer.deserialize(descriptor.version, in); } components.put(type, component); } return components; }
public int compareTo(MetadataComponent o) { return this.getType().compareTo(o.getType()); } }