Improved test, fixed bug
This commit is contained in:
parent
def99f7a7c
commit
7a84d1e220
@ -66,7 +66,8 @@ public class MPString implements MPType<String>, CharSequence {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void pack(OutputStream out) throws IOException {
|
public void pack(OutputStream out) throws IOException {
|
||||||
int size = value.length();
|
byte[] bytes = value.getBytes(encoding);
|
||||||
|
int size = bytes.length;
|
||||||
if (size < 32) {
|
if (size < 32) {
|
||||||
out.write(FIXSTR_PREFIX + size);
|
out.write(FIXSTR_PREFIX + size);
|
||||||
} else if (size < STR8_LIMIT) {
|
} else if (size < STR8_LIMIT) {
|
||||||
@ -79,7 +80,7 @@ public class MPString implements MPType<String>, CharSequence {
|
|||||||
out.write(STR32_PREFIX);
|
out.write(STR32_PREFIX);
|
||||||
out.write(ByteBuffer.allocate(4).putInt(size).array());
|
out.write(ByteBuffer.allocate(4).putInt(size).array());
|
||||||
}
|
}
|
||||||
out.write(value.getBytes(encoding));
|
out.write(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -63,7 +63,7 @@ public class ReaderTest {
|
|||||||
new MPInteger(42),
|
new MPInteger(42),
|
||||||
new MPMap<>(new HashMap<MPNil, MPNil>()),
|
new MPMap<>(new HashMap<MPNil, MPNil>()),
|
||||||
new MPNil(),
|
new MPNil(),
|
||||||
new MPString("yay!") // TODO: emoji
|
new MPString("yay! \uD83E\uDD13")
|
||||||
);
|
);
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
array.pack(out);
|
array.pack(out);
|
||||||
|
Loading…
Reference in New Issue
Block a user