...

Source file src/github.com/gogo/protobuf/test/importcustom-issue389/imported/b.go

Documentation: github.com/gogo/protobuf/test/importcustom-issue389/imported

     1  package imported
     2  
     3  import (
     4  	"encoding/json"
     5  
     6  	"github.com/gogo/protobuf/proto"
     7  )
     8  
     9  type B struct {
    10  	A
    11  }
    12  
    13  func (b B) Equal(other B) bool {
    14  	return b.A.Equal(other.A)
    15  }
    16  
    17  func (b B) Size() int {
    18  	return b.A.Size()
    19  }
    20  
    21  func NewPopulatedB(r randyA) *B {
    22  	a := NewPopulatedA(r, true)
    23  	if a == nil {
    24  		return nil
    25  	}
    26  	return &B{*a}
    27  }
    28  
    29  func (b B) Marshal() ([]byte, error) {
    30  	return proto.Marshal(&b.A)
    31  }
    32  
    33  func (b *B) Unmarshal(data []byte) error {
    34  	a := &A{}
    35  	err := proto.Unmarshal(data, a)
    36  	if err != nil {
    37  		return err
    38  	}
    39  	b.A = *a
    40  	return nil
    41  }
    42  
    43  func (b B) MarshalJSON() ([]byte, error) {
    44  	return json.Marshal(b.A)
    45  }
    46  
    47  func (b *B) UnmarshalJSON(data []byte) error {
    48  	a := &A{}
    49  	err := json.Unmarshal(data, a)
    50  	if err != nil {
    51  		return err
    52  	}
    53  	*b = B{A: *a}
    54  	return nil
    55  }
    56  

View as plain text