MCPcopy Create free account
hub / github.com/ByteStorage/FlyDB / UnmarshalBinary

Method UnmarshalBinary

structure/zset.go:1133–1159  ·  view source on GitHub ↗

UnmarshalBinary de-serializes the given byte slice into FZSet instance it uses MessagePack format for de-serialization Returns an error if the decoding of size or insertion of node fails. Parameters: data : a slice of bytes to be decoded Returns: An error that will be nil if the function succeeds.

(data []byte)

Source from the content-addressed store, hash-verified

1131// Returns:
1132// An error that will be nil if the function succeeds.
1133func (fzs *FZSet) UnmarshalBinary(data []byte) (err error) {
1134 // NewMessagePackDecoder creates a new MessagePack decoder with the provided data
1135 dec := encoding.NewMessagePackDecoder(data)
1136
1137 var size int
1138 // Decode the size of the data structure
1139 if err = dec.Decode(&size); err != nil {
1140 return err // error handling if something goes wrong with decoding
1141 }
1142
1143 // Iterate through each node in the data structure
1144 for i := 0; i < size; i++ {
1145 // Create an empty instance of ZSetValue for each node
1146 slValue := ZSetValue{}
1147
1148 // Decode each node onto the empty ZSetValue instance
1149 if err = dec.Decode(&slValue); err != nil {
1150 return err // error handling if something goes wrong with decoding
1151 }
1152
1153 // Insert the decoded node into the FZSet instance
1154 if err = fzs.InsertNode(slValue.score, slValue.member, slValue.value); err != nil {
1155 return err
1156 }
1157 }
1158 return // if all nodes are correctly decoded and inserted, return with nil error
1159}
1160
1161// MarshalBinary serializes the FZSet instance into a byte slice.
1162// It uses MessagePack format for serialization

Callers 9

SetBitMethod · 0.45
SetBitsMethod · 0.45
GetBitMethod · 0.45
DelBitMethod · 0.45
DelBitsMethod · 0.45
BitCountMethod · 0.45
BitOpMethod · 0.45
newBitSetFunction · 0.45

Calls 3

InsertNodeMethod · 0.95
NewMessagePackDecoderFunction · 0.92
DecodeMethod · 0.45

Tested by 1