-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AddBinary(data) result differs from the result of AddString(string(data)) #324
Comments
But users can push arbitrary bytes anyway, by wrapping them to string. So that is strange constraint. Users can do same, but encoder should make extra allocations. |
There are a few issues at play. First, base64-encoding. This is specific to the JSON encoder, since that's the usual way to represent binary data in JSON. When/if we get around to adding a msgpack encoder, it won't need to base64-encode its input, since msgpack is a binary encoding scheme. Second, whether we want an
I'm certainly willing to look at a PR for this, but (unfortunately) it'll need to come very quickly - adding to the encoder APIs is a breaking change that I won't accept after version 1.0, which I'm hoping to cut next week. |
This is a breaking change that adds a `AddByteString` to `zapcore.ObjectEncoder`, `AppendByteString` to `zapcore.PrimitiveArrayEncoder`. This API optimizes logging UTF-8 encoded []byte data. Fixes uber-go#324.
This is a breaking change that adds a `AddByteString` to `zapcore.ObjectEncoder`, `AppendByteString` to `zapcore.PrimitiveArrayEncoder`. This API optimizes logging UTF-8 encoded []byte data. Fixes uber-go#324.
This is a breaking change that adds a `AddByteString` to `zapcore.ObjectEncoder`, `AppendByteString` to `zapcore.PrimitiveArrayEncoder`. This API optimizes logging UTF-8 encoded []byte data. Fixes uber-go#324.
This is a breaking change that adds a `AddByteString` to `zapcore.ObjectEncoder`, `AppendByteString` to `zapcore.PrimitiveArrayEncoder`. This API optimizes logging UTF-8 encoded []byte data. Fixes uber-go#324.
This is a breaking change that adds a `AddByteString` to `zapcore.ObjectEncoder`, `AppendByteString` to `zapcore.PrimitiveArrayEncoder`. This API optimizes logging UTF-8 encoded []byte data. Fixes uber-go#324.
This is a breaking change that adds a `AddByteString` to `zapcore.ObjectEncoder`, `AppendByteString` to `zapcore.PrimitiveArrayEncoder`. This API optimizes logging UTF-8 encoded []byte data. Fixes uber-go#324.
This is a breaking change that adds bytestring APIs (to log UTF-8 encoded bytes) to ObjectEncoder and ArrayEncoder. To actually save allocations along this path, I also benchmarked adding a []byte to the field union; this reduces the allocation count for bytestrings, but increases the cost of adding fields by ~50%. Fixes #324.
In Go
[]byte
andstring
is freely converted between. But binary data is encoded as base64 string now. It is very surprising, and seem to be uncommon whenzap.Binary(key, data)
andzap.String(key, string(zap))
produce different result.I think that it is caller responsibility to encode binary data, and it should can choose encoding itself.
Also, this strange behaviour requires extra allocations for callers that don't want to convert their
[]byte
to base64.The text was updated successfully, but these errors were encountered: