github.com/m3db/m3@v1.5.0/src/msg/protocol/proto/types.go (about) 1 // Copyright (c) 2018 Uber Technologies, Inc. 2 // 3 // Permission is hereby granted, free of charge, to any person obtaining a copy 4 // of this software and associated documentation files (the "Software"), to deal 5 // in the Software without restriction, including without limitation the rights 6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 // copies of the Software, and to permit persons to whom the Software is 8 // furnished to do so, subject to the following conditions: 9 // 10 // The above copyright notice and this permission notice shall be included in 11 // all copies or substantial portions of the Software. 12 // 13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 // THE SOFTWARE. 20 21 package proto 22 23 import ( 24 "io" 25 26 xio "github.com/m3db/m3/src/x/io" 27 "github.com/m3db/m3/src/x/pool" 28 ) 29 30 // Marshaler can be marshalled. 31 type Marshaler interface { 32 // Size returns the size of the marshalled bytes. 33 Size() int 34 35 // MarshalTo marshals the marshaler into the given byte slice. 36 MarshalTo(data []byte) (int, error) 37 } 38 39 // Unmarshaler can be unmarshalled from bytes. 40 type Unmarshaler interface { 41 // Unmarshal unmarshals the unmarshaler from the given byte slice. 42 Unmarshal(data []byte) error 43 } 44 45 // Encoder encodes the marshaler. 46 type Encoder interface { 47 // Encode encodes the marshaler. 48 Encode(m Marshaler) error 49 50 // Bytes returns the encoded bytes, the bytes could be reused by 51 // the next encode call. 52 Bytes() []byte 53 } 54 55 // Decoder decodes into an unmarshaler. 56 type Decoder interface { 57 // Decode decodes the unmarshaler. 58 Decode(m Unmarshaler) error 59 60 // ResetReader resets the reader. 61 ResetReader(r io.Reader) 62 } 63 64 // Options configures a encoder or decoder. 65 type Options interface { 66 // MaxMessageSize returns the maximum message size. 67 MaxMessageSize() int 68 69 // SetMaxMessageSize sets the maximum message size. 70 SetMaxMessageSize(value int) Options 71 72 // BytesPool returns the bytes pool. 73 BytesPool() pool.BytesPool 74 75 // SetBytesPool sets the bytes pool. 76 SetBytesPool(value pool.BytesPool) Options 77 78 // SetRWOptions sets RW options. 79 SetRWOptions(value xio.Options) Options 80 81 // RWOptions returns the RW options. 82 RWOptions() xio.Options 83 }