AppendBool append a boolean value to buffer and advances byte/bit offset.
(value bool)
| 157 | |
| 158 | // AppendBool append a boolean value to buffer and advances byte/bit offset. |
| 159 | func (b *BufferWriter) AppendBool(value bool) error { |
| 160 | if b.offset >= len(b.buffer) { |
| 161 | return StackError(nil, "Failed to write bool to buffer at offset (%d,%d)", b.offset, b.bitOffset) |
| 162 | } |
| 163 | // Need to advance to the next byte. |
| 164 | if value { |
| 165 | b.buffer[b.offset] |= 0x1 << uint8(b.bitOffset) |
| 166 | } else { |
| 167 | b.buffer[b.offset] &^= 0x1 << uint8(b.bitOffset) |
| 168 | } |
| 169 | if b.bitOffset == 7 { |
| 170 | b.offset++ |
| 171 | b.bitOffset = 0 |
| 172 | } else { |
| 173 | b.bitOffset++ |
| 174 | } |
| 175 | return nil |
| 176 | } |
| 177 | |
| 178 | // AppendInt8 writes a int8 value to buffer and advances offset. |
| 179 | func (b *BufferWriter) AppendInt8(value int8) error { |
no test coverage detected