-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Changes in ProtoBuf.js 2
ProtoBuf.js 2 uses lots of functionality from ByteBuffer.js 2, like an easier way to encode/decode to/from base64 and hex:
-
ProtoBuf.Builder.Message#encodeABEncodes to an ArrayBuffer -
ProtoBuf.Builder.Message#toArrayBufferAlias for encodeAB -
ProtoBuf.Builder.Message#encodeNBEncodes to a node Buffer -
ProtoBuf.Builder.Message#toBufferAlias for #encodeNB -
ProtoBuf.Builder.Message#encode64Encodes to a base64 encoded string -
ProtoBuf.Builder.Message#encodeHexEncodes to a hex encoded string -
ProtoBuf.Builder.Message#toString(enc)Encodes to base64, hex, utf8 (not recommended), debug -
ProtoBuf.Builder.Message#decode(buffer, enc)Decodes with the given encoding if buffer is a string -
ProtoBuf.Builder.Message#decode64Decodes from base64 -
ProtoBuf.Builder.Message#decodeHexDecodes from hex
ByteBuffer 1.x provided a means of debugability through its #toHex method that returned the hex representation of the underlying buffer including marked offsets. This led to some confusion and has changed. #toHex now returns a plain hex encoded representation while #toString("debug") returns what ByteBuffer 1.x previously returned for #toHex but without any line breaks.
Encoding of messages with missing required fields now reports this through an error containing the rest of the encoded message in the same manner as decoding does. Property names on the thrown err have changed to err.encoded (still encoded message in the specified encoding) respectively err.decoded (decoded message with missing required fields).
Message and service constructors no longer are named functions as the eval() logic regularily caused trouble.
proto2js now pulls imports into the resulting JSON output instead of just returning the file names for further processing.
Services are now available through a straight-forward API.
-
ProtoBuf.protoFromFilehas becomeProtoBuf.loadProtoFilebut is kept as an alias -
ProtoBuf.protoFromStringhas becomeProtoBuf.loadProtobut is kept as an alias -
ProtoBuf.fromJsonFilehas been added -
ProtoBuf.fromJsonhas been added