FasterXML / FasterXML/jackson-dataformats-binary

Long strings encoded using streaming form

未關閉
#166 4 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
cbor
主要語言
Java
星號
347
分支
156
平均合併
3 天 3 小時
30 天內合併 PR
22

描述

In `CBORGenerator.java`, there is a limit to the length of the string that can be output before the generator will use the indefinite length encoding. The reason behind this appears to be the complexity of determining the length of the encoded byte stream when it does not fit into an internal buffer, given that the length prefix needs to be output before the data.

For now, we have changed the implementation of `_writeChunkedString(...)` to the following:
```
protected final void writeLongString(char[] text, int offset, int len) throws IOException {
CharBuffer charBuffer = CharBuffer.wrap(text, offset, len);
ByteBuffer byteBuffer = StandardCharsets.UTF_8.encode(charBuffer);
int byteLen = byteBuffer.remaining();
_writeLengthMarker(PREFIX_TYPE_TEXT, byteLen);
_writeBytes(byteBuffer.array(), byteBuffer.position(), byteLen);
}
```

It should also be possible to use the existing UTF-8 encoder to write the encoding out in pieces with the addition of a `int encodedLength(...)` method to precompute and output the length.

Also, thanks for the awesome library!

貢獻指南

這個儲存庫沒有索引到貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。