-
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#encodeAB
Encodes to an ArrayBuffer -
ProtoBuf.Builder.Message#toArrayBuffer
Alias for encodeAB -
ProtoBuf.Builder.Message#encodeNB
Encodes to a node Buffer -
ProtoBuf.Builder.Message#toBuffer
Alias for #encodeNB -
ProtoBuf.Builder.Message#encode64
Encodes to a base64 encoded string -
ProtoBuf.Builder.Message#encodeHex
Encodes 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#decode64
Decodes from base64 -
ProtoBuf.Builder.Message#decodeHex
Decodes 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.protoFromFile
has becomeProtoBuf.loadProtoFile
but is kept as an alias -
ProtoBuf.protoFromString
has becomeProtoBuf.loadProto
but is kept as an alias -
ProtoBuf.fromJsonFile
has been added -
ProtoBuf.fromJson
has been added