private EntityData.PackedEntity.Builder serializeEntityFull(EntityRef entityRef, FieldSerializeCheck<Component> fieldCheck) { EntityData.PackedEntity.Builder entity = EntityData.PackedEntity.newBuilder(); ByteString.Output fieldIds = ByteString.newOutput(); ByteString.Output componentFieldCounts = ByteString.newOutput(); for (Component component : entityRef.iterateComponents()) { if (!componentSerializeCheck.serialize(componentLibrary.getMetadata(component.getClass()))) { continue; } serializeComponentFull(component, false, fieldCheck, entity, fieldIds, componentFieldCounts, true); } entity.setFieldIds(fieldIds.toByteString()); entity.setComponentFieldCounts(componentFieldCounts.toByteString()); return entity; }
private EntityData.PackedEntity.Builder serializeEntityDelta(EntityRef entityRef, Prefab prefab, FieldSerializeCheck<Component> fieldCheck) { EntityData.PackedEntity.Builder entity = EntityData.PackedEntity.newBuilder(); entity.setParentPrefabUri(prefab.getName()); Set<Class<? extends Component>> presentClasses = Sets.newHashSet(); ByteString.Output fieldIds = ByteString.newOutput(); ByteString.Output componentFieldCounts = ByteString.newOutput(); for (Component component : entityRef.iterateComponents()) { if (!componentSerializeCheck.serialize(componentLibrary.getMetadata(component.getClass()))) { continue; } presentClasses.add(component.getClass()); Component prefabComponent = prefab.getComponent(component.getClass()); if (prefabComponent == null) { serializeComponentFull(component, false, fieldCheck, entity, fieldIds, componentFieldCounts, true); } else { serializeComponentDelta(prefabComponent, component, fieldCheck, entity, fieldIds, componentFieldCounts, true); } } entity.setFieldIds(fieldIds.toByteString()); entity.setComponentFieldCounts(componentFieldCounts.toByteString()); for (Component prefabComponent : prefab.iterateComponents()) { if (!presentClasses.contains(prefabComponent.getClass()) && componentSerializeCheck.serialize(componentLibrary.getMetadata(prefabComponent.getClass()))) { entity.addRemovedComponent(idTable.get(prefabComponent.getClass())); } } return entity; }
/** Converts the value to a quoted regular expression. */ public static ByteString literalRegex(ByteString value) { ByteString.Output output = ByteString.newOutput(value.size() * 2); ByteIterator it = value.iterator(); writeLiteralRegex(it, output); return output.toByteString(); }
private void checkSignature(SignableVertexSpec vertex, ByteString vertexBinary, SubmitWorkRequestProto request, String tokenUserName) throws SecurityException, IOException { if (!request.hasWorkSpecSignature()) { logSecurityErrorRarely(tokenUserName); throw new SecurityException("Unsigned fragment not allowed"); } if (vertexBinary == null) { ByteString.Output os = ByteString.newOutput(); vertex.writeTo(os); vertexBinary = os.toByteString(); } try { signer.checkSignature(vertexBinary.toByteArray(), request.getWorkSpecSignature().toByteArray(), (int)vertex.getSignatureKeyId()); } catch (SecurityException ex) { logSecurityErrorRarely(tokenUserName); throw ex; } if (!vertex.hasUser() || !vertex.getUser().equals(tokenUserName)) { logSecurityErrorRarely(tokenUserName); throw new SecurityException("LLAP token is for " + tokenUserName + " but the fragment is for " + (vertex.hasUser() ? vertex.getUser() : null)); } }
EntityData.PackedEntity.Builder entity = EntityData.PackedEntity.newBuilder(); ByteString.Output fieldIds = ByteString.newOutput(); ByteString.Output componentFieldCounts = ByteString.newOutput(); for (Class<? extends Component> componentType : added) { Component component = entityRef.getComponent(componentType);
private void serializeEventInfo(NetData.ServerInfoMessage.Builder serverInfoMessageBuilder) { Map<Class<? extends Event>, Integer> eventIdTable = eventSerializer.getIdMapping(); for (Map.Entry<Class<? extends Event>, Integer> eventMapping : eventIdTable.entrySet()) { ByteString.Output fieldIds = ByteString.newOutput(); EventMetadata<?> metadata = eventLibrary.getMetadata(eventMapping.getKey()); NetData.SerializationInfo.Builder info = NetData.SerializationInfo.newBuilder() .setId(eventMapping.getValue()) .setName(metadata.getUri().toString()); for (FieldMetadata<?, ?> field : metadata.getFields()) { fieldIds.write(field.getId()); info.addFieldName(field.getName()); } info.setFieldIds(fieldIds.toByteString()); serverInfoMessageBuilder.addEvent(info); } }
private void serializeComponentInfo(NetData.ServerInfoMessage.Builder serverInfoMessageBuilder) { Map<Class<? extends Component>, Integer> componentIdTable = entitySerializer.getIdMapping(); for (Map.Entry<Class<? extends Component>, Integer> componentIdMapping : componentIdTable.entrySet()) { ByteString.Output fieldIds = ByteString.newOutput(); ComponentMetadata<?> metadata = componentLibrary.getMetadata(componentIdMapping.getKey()); NetData.SerializationInfo.Builder info = NetData.SerializationInfo.newBuilder() .setId(componentIdMapping.getValue()) .setName(metadata.getUri().toString()); for (FieldMetadata<?, ?> field : metadata.getFields()) { fieldIds.write(field.getId()); info.addFieldName(field.getName()); } info.setFieldIds(fieldIds.toByteString()); serverInfoMessageBuilder.addComponent(info); } }
/** * Serializes an event. * * @param event * @return The serialized event * @throws org.terasology.persistence.typeHandling.SerializationException if an error occurs during serialization */ public EntityData.Event serialize(Event event) { EventMetadata<?> eventMetadata = eventLibrary.getMetadata(event.getClass()); if (eventMetadata == null) { throw new SerializationException("Unregistered event type: " + event.getClass()); } else if (!eventMetadata.isConstructable()) { throw new SerializationException("Cannot serialize event '" + eventMetadata + "' - lacks default constructor so cannot be deserialized"); } EntityData.Event.Builder eventData = EntityData.Event.newBuilder(); serializeEventType(event, eventData); Serializer eventSerializer = typeSerializationLibrary.getSerializerFor(eventMetadata); ByteString.Output fieldIds = ByteString.newOutput(); for (ReplicatedFieldMetadata field : eventMetadata.getFields()) { if (field.isReplicated()) { EntityData.Value serializedValue = ((ProtobufPersistedData) eventSerializer.serialize(field, event, serializationContext)).getValue(); if (serializedValue != null) { eventData.addFieldValue(serializedValue); fieldIds.write(field.getId()); } } } eventData.setFieldIds(fieldIds.toByteString()); return eventData.build(); }
Builder(int maxDataLength) { out = ByteString.newOutput(64*1024); cos = CodedOutputStream.newInstance(out); this.maxDataLength = maxDataLength; }
/** * <p>quoteRegularExpression.</p> * * @param unquoted an array of byte. * @return an array of byte. * @throws java.io.IOException if any. */ public static ByteString quoteRegularExpression(byte[] unquoted) throws IOException { ByteString.Output output = ByteString.newOutput(unquoted.length * 2); writeQuotedRegularExpression(output, unquoted); return output.toByteString(); }
private void addPartialCellChunk(ReadRowsResponse.CellChunk chunk) throws IOException { if (outputStream == null) { outputStream = ByteString.newOutput(); } chunk.getValue().writeTo(outputStream); }
/** * <p>quoteRegularExpression.</p> * * @param unquoted an array of byte. * @return an array of byte. * @throws java.io.IOException if any. */ public static ByteString quoteRegularExpression(byte[] unquoted) throws IOException { ByteString.Output output = ByteString.newOutput(unquoted.length * 2); writeQuotedRegularExpression(output, unquoted); return output.toByteString(); }
public static ByteString convertCredentialsToProto(Credentials credentials) { if (credentials == null) { return null; } Output output = ByteString.newOutput(); DataOutputStream dos = new DataOutputStream(output); try { credentials.writeTokenStorageToStream(dos); return output.toByteString(); } catch (IOException e) { throw new TezUncheckedException("Failed to serialize Credentials", e); } }
/** Converts the value to a quoted regular expression. */ public static ByteString literalRegex(ByteString value) { Output output = ByteString.newOutput(value.size() * 2); ByteIterator it = value.iterator(); try { writeLiteralRegex(it, output); } catch (IOException e) { throw new RuntimeException("Unexpected io error converting regex", e); } return output.toByteString(); }
/** Converts the value to a quoted regular expression. */ public static ByteString literalRegex(ByteString value) { ByteString.Output output = ByteString.newOutput(value.size() * 2); ByteIterator it = value.iterator(); writeLiteralRegex(it, output); return output.toByteString(); }
@InterfaceStability.Evolving @InterfaceAudience.LimitedPrivate({"hive, pig"}) public static MRRuntimeProtos.MRSplitProto createSplitProto( org.apache.hadoop.mapred.InputSplit oldSplit) throws IOException { MRRuntimeProtos.MRSplitProto.Builder builder = MRRuntimeProtos.MRSplitProto.newBuilder(); builder.setSplitClassName(oldSplit.getClass().getName()); ByteString.Output os = ByteString .newOutput(SPLIT_SERIALIZED_LENGTH_ESTIMATE); oldSplit.write(new NonSyncDataOutputStream(os)); ByteString splitBs = os.toByteString(); builder.setSplitBytes(splitBs); return builder.build(); }
/** * {@inheritDoc} */ @Override public Filter adapt(FilterAdapterContext context, PrefixFilter filter) throws IOException { ByteString.Output output = ByteString.newOutput(filter.getPrefix().length * 2); ReaderExpressionHelper.writeQuotedRegularExpression(output, filter.getPrefix()); // Unquoted all bytes: output.write(ReaderExpressionHelper.ALL_QUALIFIERS_BYTES); return FILTERS.key().regex(output.toByteString()); }
/** * {@inheritDoc} */ @Override public Filter adapt(FilterAdapterContext context, PrefixFilter filter) throws IOException { ByteString.Output output = ByteString.newOutput(filter.getPrefix().length * 2); ReaderExpressionHelper.writeQuotedRegularExpression(output, filter.getPrefix()); // Unquoted all bytes: output.write(ReaderExpressionHelper.ALL_QUALIFIERS_BYTES); return FILTERS.key().regex(output.toByteString()); }
/** {@inheritDoc} */ @Override public Filter adapt(FilterAdapterContext context, ColumnPrefixFilter filter) throws IOException { byte[] prefix = filter.getPrefix(); // Quoting for RE2 can result in at most length * 2 characters written. Pre-allocate // that much space in the ByteString.Output to prevent reallocation later. ByteString.Output outputStream = ByteString.newOutput(prefix.length * 2); ReaderExpressionHelper.writeQuotedExpression(outputStream, prefix); outputStream.write(ReaderExpressionHelper.ALL_QUALIFIERS_BYTES); Filter qualifierFilter = FILTERS.qualifier().regex(outputStream.toByteString()); return FILTERS.chain().filter(qualifierFilter); }
/** {@inheritDoc} */ @Override public Filter adapt(FilterAdapterContext context, ColumnPrefixFilter filter) throws IOException { byte[] prefix = filter.getPrefix(); // Quoting for RE2 can result in at most length * 2 characters written. Pre-allocate // that much space in the ByteString.Output to prevent reallocation later. ByteString.Output outputStream = ByteString.newOutput(prefix.length * 2); ReaderExpressionHelper.writeQuotedExpression(outputStream, prefix); outputStream.write(ReaderExpressionHelper.ALL_QUALIFIERS_BYTES); Filter qualifierFilter = FILTERS.qualifier().regex(outputStream.toByteString()); return FILTERS.chain().filter(qualifierFilter); }