blob: 9e064ff91bbe1b360b940fda936ca6b7b4e71165 [file] [log] [blame]
Jonathan Hart44bdbfc2020-04-14 17:45:47 -07001/*
2 * Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior University
3 * Copyright (c) 2011, 2012 Open Networking Foundation
4 * Copyright 2013, Big Switch Networks, Inc. This library was generated by the LoxiGen Compiler.
5 * Copyright 2018, Red Hat, Inc.
6 */
7package goloxi
8
9import (
10 "bytes"
11 "encoding/binary"
12)
13
14type Encoder struct {
15 buffer *bytes.Buffer
16}
17
18func NewEncoder() *Encoder {
19 return &Encoder{
20 buffer: new(bytes.Buffer),
21 }
22}
23
24func (e *Encoder) PutChar(c byte) {
25 e.buffer.WriteByte(c)
26}
27
28func (e *Encoder) PutUint8(i uint8) {
29 e.buffer.WriteByte(i)
30}
31
32func (e *Encoder) PutUint16(i uint16) {
33 var tmp [2]byte
34 binary.BigEndian.PutUint16(tmp[0:2], i)
35 e.buffer.Write(tmp[:])
36}
37
38func (e *Encoder) PutUint32(i uint32) {
39 var tmp [4]byte
40 binary.BigEndian.PutUint32(tmp[0:4], i)
41 e.buffer.Write(tmp[:])
42}
43
44func (e *Encoder) PutUint64(i uint64) {
45 var tmp [8]byte
46 binary.BigEndian.PutUint64(tmp[0:8], i)
47 e.buffer.Write(tmp[:])
48}
49
50func (e *Encoder) PutUint128(i Uint128) {
51 var tmp [16]byte
52 binary.BigEndian.PutUint64(tmp[0:8], i.Hi)
53 binary.BigEndian.PutUint64(tmp[8:16], i.Lo)
54 e.buffer.Write(tmp[:])
55}
56
57func (e *Encoder) Write(b []byte) {
58 e.buffer.Write(b)
59}
60
61func (e *Encoder) Bytes() []byte {
62 return e.buffer.Bytes()
63}