Results 1 to 2 of 2

Thread: SpringData + Protobuf + Mongodb magic @ID handler

  1. #1
    Join Date
    Sep 2011
    Location
    Dublin Ireland
    Posts
    16

    Question SpringData + Protobuf + Mongodb magic @ID handler

    Hi,

    I was testing storage of a Google Protobuf document into mongodb and decided for simplicity to use "." dot notation for the "_id" field in the database.

    So the "_id" entry would be made from 3 fields from the protobuf as follows:

    Code:
    "_id" : "3936303865666539656633653461333362373536363664363534353766363831.517f7dfb.PDG*"
    Code:
    message Message {
    
        message Identity {
            required string group = 1; // 32 chars
            required string epoch = 2; // 4 hex chars
            required string sender = 3; // 3 chars 
        }
        required Identity identity = 1; // 39 char   
    
        required string state = 2; // 1 char
    
        message Signal { // 64 chars
      ... etc
        }
        required Signal signal = 3;   
    }
    I implemented a MessageReadConverter & MessageWriteConverter for the spring data Converter all works great.

    My questions is what part of the architect managed to convert the "." fields during reading the mongodb data into the correct Identity part of my protobuf object ?

    The writer is:

    Code:
        @Override
        public DBObject convert(Lwwk.Message msg) {
            final DBObject dbo = new BasicDBObject();        
            final String jsonSignal = JsonFormat.printToString(msg.getSignal());               
            dbo.put("_id", Elements.toIdentityString(msg.getIdentity()));
            dbo.put("state", msg.getState());
            
            // TODO: this seems so wrong but it works
            dbo.putAll((BSONObject) JSON.parse(jsonSignal)); // capture sub docs
            return dbo;
        }
    and the reader:

    Code:
        @Override
        public Message convert(DBObject o) {        
            // TODO: it works out the delimited ID itself ?
            return composer.buildPartial();
        }
    and a correctly built protobuf object is populated:

    Code:
    2539 [main] INFO net.lwwk.services.core.BlackBox - GOT 
    identity {
      group: "6136653462636639323363393464656439343933306130393939323135656563"
      epoch: "517f8088"
      sender: "PDG*"
    }
    state: "?"
    signal {
    ...etc
    }

  2. #2
    Join Date
    Sep 2011
    Location
    Dublin Ireland
    Posts
    16

    Default

    If I comment out the reader in the spring config no longer works.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •