Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: talostrading/sonic
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.5.1
Choose a base ref
...
head repository: talostrading/sonic
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.5.2
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Jul 28, 2023

  1. Expose bip buffer wrapped

    sergiu128 committed Jul 28, 2023
    Copy the full SHA
    be3ec21 View commit details
  2. Test buffer wrapping

    sergiu128 committed Jul 28, 2023
    Copy the full SHA
    20264dd View commit details
Showing with 34 additions and 10 deletions.
  1. +2 −2 bip_buffer.go
  2. +32 −8 bip_buffer_test.go
4 changes: 2 additions & 2 deletions bip_buffer.go
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@ func (buf *BipBuffer) Reset() {
buf.claimTail = 0
}

func (buf *BipBuffer) wrapped() bool {
func (buf *BipBuffer) Wrapped() bool {
return buf.wrappedTail-buf.wrappedHead > 0
}

@@ -63,7 +63,7 @@ func (buf *BipBuffer) Claim(n int) []byte {
claimHead int
freeSpace int
)
if buf.wrapped() {
if buf.Wrapped() {
claimHead = buf.wrappedTail
freeSpace = buf.head - buf.wrappedTail
} else {
40 changes: 32 additions & 8 deletions bip_buffer_test.go
Original file line number Diff line number Diff line change
@@ -142,35 +142,59 @@ func TestBipBufferClaimAfterWrapping(t *testing.T) {
b[2] = 218
b[3] = 56
}
b := buf.Commit(4)
if !bytes.Equal(b, []byte{7, 22, 218, 56}) {
t.Fatal("wrong committed")
{
b := buf.Commit(4)
if !bytes.Equal(b, []byte{7, 22, 218, 56}) {
t.Fatal("wrong committed")
}
buf.Consume(2)
}
buf.Consume(2)
{
b := buf.Claim(4)
if len(b) != 2 {
t.Fatal("wrong claim")
}
b[0] = 49
b[1] = 81

if buf.Wrapped() {
t.Fatal("should not yet report wrapped, need to commit first")
}
}
b = buf.Commit(2)
if !bytes.Equal(b, []byte{49, 81}) {
t.Fatal("wrong committed")
{
b := buf.Commit(2)
if !bytes.Equal(b, []byte{49, 81}) {
t.Fatal("wrong committed")
}

if !buf.Wrapped() {
t.Fatal("should report as wrapped")
}
}
{
b := buf.Head()
if !bytes.Equal(b, []byte{218, 56}) {
t.Fatal("wrong data")
}
buf.Consume(2)

if buf.Wrapped() {
t.Fatal("should not report wrapped")
}
}
buf.Consume(2)
{
b := buf.Head()
if !bytes.Equal(b, []byte{49, 81}) {
t.Fatal("wrong data")
}

buf.Consume(2)
if buf.Head() != nil {
t.Fatal("should be empty")
}
if buf.Wrapped() {
t.Fatal("empty buffer cannot be wrapped")
}
}
}