MCPcopy Create free account
hub / github.com/bits-and-blooms/bitset / ExampleBitSet_WriteTo

Function ExampleBitSet_WriteTo

example_test.go:235–258  ·  view source on GitHub ↗

ExampleBitSet_WriteTo serializes a BitSet to a stream and reads it back with ReadFrom. The encoding is portable across platforms.

()

Source from the content-addressed store, hash-verified

233// ExampleBitSet_WriteTo serializes a BitSet to a stream and reads it back with
234// ReadFrom. The encoding is portable across platforms.
235func ExampleBitSet_WriteTo() {
236 b := New(100).Set(10).Set(20).Set(99)
237
238 var buf bytes.Buffer
239
240 _, err := b.WriteTo(&buf)
241 if err != nil {
242 panic(err)
243 }
244
245 // ReadFrom reuses the receiver's storage where possible.
246 restored := New(0)
247
248 _, err = restored.ReadFrom(&buf)
249 if err != nil {
250 panic(err)
251 }
252
253 fmt.Println("equal:", restored.Equal(b))
254 fmt.Println("bits:", restored.String())
255 // Output:
256 // equal: true
257 // bits: {10,20,99}
258}
259
260// ExampleBitSet_MarshalJSON round-trips a BitSet through JSON. BitSet
261// implements json.Marshaler and json.Unmarshaler.

Callers

nothing calls this directly

Calls 6

NewFunction · 0.85
SetMethod · 0.80
WriteToMethod · 0.80
ReadFromMethod · 0.80
EqualMethod · 0.80
StringMethod · 0.80

Tested by

no test coverage detected