Skip to content

Doesn't adhere to enum ordering #908

Open
@dignifiedquire

Description

@dignifiedquire

protobuf.js version: 6.8.0

Given a proto definition like this

// An IPFS MerkleDAG Link
message PBLink {

  // multihash of the target object
  optional bytes Hash = 1;

  // utf string name. should be unique per object
  optional string Name = 2;

  // cumulative size of target object
  optional uint64 Tsize = 3;
}

// An IPFS MerkleDAG Node
message PBNode {

  // refs to other objects
  repeated PBLink Links = 2;

  // opaque user data
  optional bytes Data = 1;
}

I would expect that Links is written before Data, but looking at the generated source code it is the other way around

if (message.Data != null && message.hasOwnProperty("Data"))
            writer.uint32(/* id 1, wireType 2 =*/10).bytes(message.Data);
        if (message.Links != null && message.Links.length)
            for (var i = 0; i < message.Links.length; ++i)
                $root.PBLink.encode(message.Links[i], writer.uint32(/* id 2, wireType 2 =*/18).fork()).ldelim();

As I am doing hash comparisons between serialised objects, this breaks quite a lot of things for me currently.

(Full source: https://github.com/ipld/js-ipld-dag-pb/tree/master/src)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions