-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
817ac6e
commit dce27ea
Showing
4 changed files
with
27 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,26 @@ | ||
package log | ||
|
||
type Record struct { | ||
length int | ||
Length int | ||
Data []byte | ||
} | ||
|
||
func NewRecord(data []byte) *Record { | ||
return &Record{ | ||
length: len(data), | ||
Length: len(data), | ||
Data: data, | ||
} | ||
} | ||
|
||
// bytes returns whole record bytes, length 4-byte metadata field plus data. | ||
func (r *Record) bytes() []byte { | ||
lengthBytes := make([]byte, intBytesSize) | ||
endian.PutUint32(lengthBytes, uint32(r.length)) | ||
endian.PutUint32(lengthBytes, uint32(r.Length)) | ||
|
||
return append(lengthBytes, r.Data...) | ||
} | ||
|
||
// totalLength returns the total length of the record, including the length 4-byte metadata field. | ||
func (r *Record) totalLength() int { | ||
return intBytesSize + r.length | ||
return intBytesSize + r.Length | ||
} |