Skip to content

Commit

Permalink
Make Streaming interfaces private to allow for safe experimentation
Browse files Browse the repository at this point in the history
  • Loading branch information
dianale31 committed Jun 4, 2021
1 parent b2ee488 commit 7fadcdf
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
46 changes: 46 additions & 0 deletions internal/iface/iface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) 2021 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package iface

// Interface will be used to make interfaces defined in ThriftRW private.
// Example usage:
//
// import ".../internal/iface"
//
// type PrivateInterface interface {
// interface.Interface
// Method1()
// }
type Interface interface{ private() }

// Impl is the implementation for the private interface and should also be
// referenced.
// Example usage:
//
// import ".../internal/iface"
//
// type PrivateImpl struct {
// interface.Impl
// ...
// }
type Impl struct{}

func (Impl) private() {}
7 changes: 7 additions & 0 deletions protocol/stream/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ import (
"io"

"go.uber.org/thriftrw/wire"
internal "go.uber.org/thriftrw/internal/iface"
)

// Protocol defines a specific way for a Thrift value to be encoded or
// decoded, implemented in a streaming fashion.
type Protocol interface {
internal.Interface // this interface is meant for internal implementations only

// Writer returns a streaming implementation of an encoder for a
// Thrift value.
Writer(w io.Writer) Writer
Expand Down Expand Up @@ -72,6 +75,8 @@ type ListHeader struct {
// Writer defines an encoder for a Thrift value, implemented in a streaming
// fashion.
type Writer interface {
internal.Interface // this interface is meant for internal implementations only

WriteBool(b bool) error
WriteInt8(i int8) error
WriteInt16(i int16) error
Expand All @@ -95,6 +100,8 @@ type Writer interface {
// Reader defines an decoder for a Thrift value, implemented in a streaming
// fashion.
type Reader interface {
internal.Interface // this interface is meant for internal implementations only

ReadBool() (bool, error)
ReadInt8() (int8, error)
ReadInt16() (int16, error)
Expand Down

0 comments on commit 7fadcdf

Please sign in to comment.