Pass io to the encoder in to_cbor + regression test

dev
Alberto Restifo 2020-09-29 20:29:33 +02:00
parent 2e76c0b6d3
commit e05b209ed3
2 changed files with 10 additions and 1 deletions

View File

@ -58,4 +58,13 @@ describe "to_cbor" do
encoder.to_slice.hexdump.should eq(Bytes[0xc1, 0x1a, 0x51, 0x4b, 0x67, 0xb0].hexdump)
end
end
describe "encodes to an IO" do
it "encodes a string" do
io = IO::Memory.new
"a".to_cbor(io)
io.to_slice.should eq(Bytes[0x61, 0x61])
end
end
end

View File

@ -6,7 +6,7 @@ class Object
end
def to_cbor(io : IO)
encoder = CBOR::Encoder.new
encoder = CBOR::Encoder.new(io)
to_cbor(encoder)
self
end