Package com.google.protobuf

Examples of com.google.protobuf.DynamicMessage$Builder


  {
    final Descriptor descriptor = getDescriptor(descriptorFileInClasspath);
    final Map<String, Object> theMap = Maps.newHashMap();

    try {
      DynamicMessage message = DynamicMessage.parseFrom(descriptor, ByteString.copyFrom(input));
      Map<Descriptors.FieldDescriptor, Object> allFields = message.getAllFields();

      for (Map.Entry<Descriptors.FieldDescriptor, Object> entry : allFields.entrySet()) {
        String name = entry.getKey().getName();
        if (theMap.containsKey(name)) {
          continue;
View Full Code Here


  private final IPersistentMap _meta;
  private final IPersistentMap ext;

  static public PersistentProtocolBufferMap create(Def def, byte[] bytes)
          throws InvalidProtocolBufferException {
    DynamicMessage message = def.parseFrom(bytes);
    return new PersistentProtocolBufferMap(null, def, message);
  }
View Full Code Here

    return new PersistentProtocolBufferMap(null, def, message);
  }

  static public PersistentProtocolBufferMap parseFrom(Def def, CodedInputStream input)
          throws IOException {
    DynamicMessage message = def.parseFrom(input);
    return new PersistentProtocolBufferMap(null, def, message);
  }
View Full Code Here

          Descriptors.FieldDescriptor key_field = type.findFieldByName("key");
          Descriptors.FieldDescriptor val_field = type.findFieldByName("val");

          ITransientMap map = (ITransientMap)OrderedMap.EMPTY.asTransient();
          while (iterator.hasNext()) {
            DynamicMessage message = (DynamicMessage)iterator.next();
            Object k = fromProtoValue(key_field, message.getField(key_field));
            Object v = fromProtoValue(val_field, message.getField(val_field));
            Object existing = map.valAt(k);

            if (existing instanceof PersistentProtocolBufferMap) {
              map = map.assoc(k, def.mapValue(field,
                                              (PersistentProtocolBufferMap)existing,
                                              (PersistentProtocolBufferMap)v));
            } else if (existing instanceof IPersistentCollection) {
              map = map.assoc(k, ((IPersistentCollection)existing).cons(v));
            } else {
              map = map.assoc(k, v);
            }
          }
          return map.persistent();
        } else if (options.getExtension(Extensions.set)) {
          Descriptors.Descriptor type = field.getMessageType();
          Descriptors.FieldDescriptor item_field = type.findFieldByName("item");
          Descriptors.FieldDescriptor exists_field = type.findFieldByName("exists");

          ITransientSet set = (ITransientSet)OrderedSet.EMPTY.asTransient();
          while (iterator.hasNext()) {
            DynamicMessage message = (DynamicMessage)iterator.next();
            Object item = fromProtoValue(item_field, message.getField(item_field));
            Boolean exists = (Boolean)message.getField(exists_field);

            if (exists) {
              set = (ITransientSet)set.conj(item);
            } else {
              try {
                set = set.disjoin(item);
              } catch (Exception e) {
                e.printStackTrace();
              }
            }
          }
          return set.persistent();
        }
      }
      List<Object> list = new ArrayList<Object>(values.size());
      while (iterator.hasNext()) {
        list.add(fromProtoValue(field, iterator.next(), use_extensions));
      }
      return PersistentVector.create(list);
    } else {
      switch (field.getJavaType()) {
        case ENUM:
          Descriptors.EnumValueDescriptor e = (Descriptors.EnumValueDescriptor)value;
          if (use_extensions &&
              field.getOptions().getExtension(Extensions.nullable) &&
              field.getOptions().getExtension(nullExtension(field)).equals(e.getNumber())) {
            return null;
          } else {
            return def.clojureEnumValue(e);
          }
        case MESSAGE:
          Def fieldDef = PersistentProtocolBufferMap.Def.create(field.getMessageType(),
                                                                this.def.namingStrategy,
                                                                this.def.sizeLimit);
          DynamicMessage message = (DynamicMessage)value;

          // Total hack because getField() doesn't return an empty array for repeated messages.
          if (field.isRepeated() && !message.isInitialized()) {
            return fromProtoValue(field, new ArrayList<Object>(), use_extensions);
          }

          return new PersistentProtocolBufferMap(null, fieldDef, message);
        default:
View Full Code Here

    @Override
    public void packRowData(FDBStore store, Session session,
                            FDBStoreData storeData, RowData rowData) {
        ensureConverter();
        DynamicMessage msg = converter.encode(rowData);
        storeData.rawValue = msg.toByteArray();       
    }
View Full Code Here

    @Override
    public void expandRowData(FDBStore store, Session session,
                              FDBStoreData storeData, RowData rowData) {
        ensureConverter();
        DynamicMessage msg;
        try {
            msg = DynamicMessage.parseFrom(converter.getMessageType(), storeData.rawValue);
        }
        catch (InvalidProtocolBufferException ex) {
            ProtobufReadException nex = new ProtobufReadException(converter.getMessageType().getName(), ex.getMessage());
View Full Code Here

    @Override
    public void put(Value value, Object object, CoderContext context) throws ConversionException {
        PersistitProtobufRow holder = (PersistitProtobufRow)object;
        ProtobufRowDataConverter converter = holder.getConverter();
        DynamicMessage msg = holder.getMessage();
        int size = msg.getSerializedSize();
        value.ensureFit(4 + size);
        int pos = value.getEncodedSize();
        Util.putInt(value.getEncodedBytes(), pos, converter.getTableId());
        pos += 4;
        CodedOutputStream cstr = CodedOutputStream.newInstance(value.getEncodedBytes(), pos, size);
        try {
            msg.writeTo(cstr);
        }
        catch (IOException ex) {
            throw new ConversionException(ex);
        }
        pos += size;
View Full Code Here

    @Override
    public void packRowData(PersistitStore store, Session session,
                            Exchange exchange, RowData rowData) {
        ensureConverter();
        DynamicMessage msg = converter.encode(rowData);
        PersistitProtobufRow holder = new PersistitProtobufRow(converter, msg);
        exchange.getValue().directPut(store.getProtobufValueCoder(), holder, null);
    }
View Full Code Here

            }
        }

        @Override
        public DynamicMessage encode(RowData rowData) {
            DynamicMessage inside =
                tableConvertersByTableId.get(rowData.getRowDefId()).encode(rowData);
            DynamicMessage.Builder builder = DynamicMessage.newBuilder(messageType);
            builder.setField(groupFieldsByTabelId.get(rowData.getRowDefId()), inside);
            return builder.build();
        }
View Full Code Here

                                RowDef rowDef,
                                Object... values)
            throws Exception {
        RowData rowDataIn = new RowData(new byte[128]);
        rowDataIn.createRow(rowDef, values, true);
        DynamicMessage msg = converter.encode(rowDataIn);
        if (false) {
            System.out.println(converter.shortFormat(msg));
        }
        RowData rowDataOut = new RowData(new byte[128]);
        converter.decode(msg, rowDataOut);
View Full Code Here

TOP

Related Classes of com.google.protobuf.DynamicMessage$Builder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.