From 09f8ee52d0b15e808126227d349947b4d7a9687f Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 28 Apr 2020 15:39:09 +0300 Subject: [PATCH] service: implement Raw field setter on RequestMetaHeader struct After recent changes Raw field is presented in RequestMetaHeader. There is a need to provide an interface of field getter/setter. This commit: * defines RawHeader interface of raw value container; * embeds RawHeader into MetaHeader interface; * implements Raw field setter on RequestMetaHeader. --- service/meta.go | 14 ++++++++++++++ service/meta_test.go | 10 ++++++++++ 2 files changed, 24 insertions(+) diff --git a/service/meta.go b/service/meta.go index 5e9886d..8602dca 100644 --- a/service/meta.go +++ b/service/meta.go @@ -25,6 +25,9 @@ type ( // VersionHeader allows get or set version of protocol request VersionHeader + + // RawHeader allows to get and set raw option of request + RawHeader } // EpochHeader interface gives possibility to get or set epoch in RPC Requests. @@ -39,6 +42,12 @@ type ( SetVersion(uint32) } + // RawHeader is an interface of the container of a boolean Raw value + RawHeader interface { + GetRaw() bool + SetRaw(bool) + } + // TTLCondition is closure, that allows to validate request with ttl. TTLCondition func(ttl uint32) error ) @@ -77,6 +86,11 @@ func (m *RequestMetaHeader) SetTTL(v uint32) { m.TTL = v } // SetEpoch sets Epoch to RequestMetaHeader. func (m *RequestMetaHeader) SetEpoch(v uint64) { m.Epoch = v } +// SetRaw is a Raw field setter. +func (m *RequestMetaHeader) SetRaw(raw bool) { + m.Raw = raw +} + // ResetMeta returns current value and sets RequestMetaHeader to empty value. func (m *RequestMetaHeader) ResetMeta() RequestMetaHeader { cp := *m diff --git a/service/meta_test.go b/service/meta_test.go index 083ccd6..388b6ce 100644 --- a/service/meta_test.go +++ b/service/meta_test.go @@ -102,3 +102,13 @@ func TestRequestMetaHeader_SetVersion(t *testing.T) { m.SetVersion(version) require.Equal(t, version, m.GetVersion()) } + +func TestRequestMetaHeader_SetRaw(t *testing.T) { + m := new(RequestMetaHeader) + + m.SetRaw(true) + require.True(t, m.GetRaw()) + + m.SetRaw(false) + require.False(t, m.GetRaw()) +}