// Code generated by ogen, DO NOT EDIT. package go_youtubekids_client import ( "math/bits" "strconv" "github.com/go-faster/errors" "github.com/go-faster/jx" "github.com/ogen-go/ogen/validate" ) // Encode implements json.Marshaler. func (s *Accessibility) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *Accessibility) encodeFields(e *jx.Encoder) { { if s.AccessibilityData.Set { e.FieldStart("accessibilityData") s.AccessibilityData.Encode(e) } } } var jsonFieldsNameOfAccessibility = [1]string{ 0: "accessibilityData", } // Decode decodes Accessibility from json. func (s *Accessibility) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode Accessibility to nil") } if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "accessibilityData": if err := func() error { s.AccessibilityData.Reset() if err := s.AccessibilityData.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"accessibilityData\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode Accessibility") } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *Accessibility) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *Accessibility) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. func (s *AccessibilityData) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *AccessibilityData) encodeFields(e *jx.Encoder) { { if s.Label.Set { e.FieldStart("label") s.Label.Encode(e) } } } var jsonFieldsNameOfAccessibilityData = [1]string{ 0: "label", } // Decode decodes AccessibilityData from json. func (s *AccessibilityData) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode AccessibilityData to nil") } if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "label": if err := func() error { s.Label.Reset() if err := s.Label.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"label\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode AccessibilityData") } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *AccessibilityData) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *AccessibilityData) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. func (s *AnchoredSectionRenderer) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *AnchoredSectionRenderer) encodeFields(e *jx.Encoder) { { if s.Title.Set { e.FieldStart("title") s.Title.Encode(e) } } { if s.Content.Set { e.FieldStart("content") s.Content.Encode(e) } } { if s.TrackingParams.Set { e.FieldStart("trackingParams") s.TrackingParams.Encode(e) } } { if s.NavigationEndpoint.Set { e.FieldStart("navigationEndpoint") s.NavigationEndpoint.Encode(e) } } { if s.CategoryAssets.Set { e.FieldStart("categoryAssets") s.CategoryAssets.Encode(e) } } { if s.CategoryType.Set { e.FieldStart("categoryType") s.CategoryType.Encode(e) } } } var jsonFieldsNameOfAnchoredSectionRenderer = [6]string{ 0: "title", 1: "content", 2: "trackingParams", 3: "navigationEndpoint", 4: "categoryAssets", 5: "categoryType", } // Decode decodes AnchoredSectionRenderer from json. func (s *AnchoredSectionRenderer) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode AnchoredSectionRenderer to nil") } if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "title": if err := func() error { s.Title.Reset() if err := s.Title.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"title\"") } case "content": if err := func() error { s.Content.Reset() if err := s.Content.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"content\"") } case "trackingParams": if err := func() error { s.TrackingParams.Reset() if err := s.TrackingParams.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"trackingParams\"") } case "navigationEndpoint": if err := func() error { s.NavigationEndpoint.Reset() if err := s.NavigationEndpoint.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"navigationEndpoint\"") } case "categoryAssets": if err := func() error { s.CategoryAssets.Reset() if err := s.CategoryAssets.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"categoryAssets\"") } case "categoryType": if err := func() error { s.CategoryType.Reset() if err := s.CategoryType.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"categoryType\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode AnchoredSectionRenderer") } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *AnchoredSectionRenderer) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *AnchoredSectionRenderer) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. func (s *AnchoredSectionRendererContent) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *AnchoredSectionRendererContent) encodeFields(e *jx.Encoder) { { if s.SectionListRenderer.Set { e.FieldStart("sectionListRenderer") s.SectionListRenderer.Encode(e) } } } var jsonFieldsNameOfAnchoredSectionRendererContent = [1]string{ 0: "sectionListRenderer", } // Decode decodes AnchoredSectionRendererContent from json. func (s *AnchoredSectionRendererContent) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode AnchoredSectionRendererContent to nil") } if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "sectionListRenderer": if err := func() error { s.SectionListRenderer.Reset() if err := s.SectionListRenderer.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"sectionListRenderer\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode AnchoredSectionRendererContent") } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *AnchoredSectionRendererContent) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *AnchoredSectionRendererContent) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. func (s *BrowseEndpoint) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *BrowseEndpoint) encodeFields(e *jx.Encoder) { { if s.BrowseId.Set { e.FieldStart("browseId") s.BrowseId.Encode(e) } } { if s.CanonicalBaseUrl.Set { e.FieldStart("canonicalBaseUrl") s.CanonicalBaseUrl.Encode(e) } } } var jsonFieldsNameOfBrowseEndpoint = [2]string{ 0: "browseId", 1: "canonicalBaseUrl", } // Decode decodes BrowseEndpoint from json. func (s *BrowseEndpoint) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode BrowseEndpoint to nil") } if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "browseId": if err := func() error { s.BrowseId.Reset() if err := s.BrowseId.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"browseId\"") } case "canonicalBaseUrl": if err := func() error { s.CanonicalBaseUrl.Reset() if err := s.CanonicalBaseUrl.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"canonicalBaseUrl\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode BrowseEndpoint") } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *BrowseEndpoint) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *BrowseEndpoint) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. func (s *BrowseRequestPayload) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *BrowseRequestPayload) encodeFields(e *jx.Encoder) { { e.FieldStart("context") s.Context.Encode(e) } { if s.Params.Set { e.FieldStart("params") s.Params.Encode(e) } } { e.FieldStart("browseId") e.Str(s.BrowseId) } } var jsonFieldsNameOfBrowseRequestPayload = [3]string{ 0: "context", 1: "params", 2: "browseId", } // Decode decodes BrowseRequestPayload from json. func (s *BrowseRequestPayload) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode BrowseRequestPayload to nil") } var requiredBitSet [1]uint8 if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "context": requiredBitSet[0] |= 1 << 0 if err := func() error { if err := s.Context.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"context\"") } case "params": if err := func() error { s.Params.Reset() if err := s.Params.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"params\"") } case "browseId": requiredBitSet[0] |= 1 << 2 if err := func() error { v, err := d.Str() s.BrowseId = string(v) if err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"browseId\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode BrowseRequestPayload") } // Validate required fields. var failures []validate.FieldError for i, mask := range [1]uint8{ 0b00000101, } { if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { // Mask only required fields and check equality to mask using XOR. // // If XOR result is not zero, result is not equal to expected, so some fields are missed. // Bits of fields which would be set are actually bits of missed fields. missed := bits.OnesCount8(result) for bitN := 0; bitN < missed; bitN++ { bitIdx := bits.TrailingZeros8(result) fieldIdx := i*8 + bitIdx var name string if fieldIdx < len(jsonFieldsNameOfBrowseRequestPayload) { name = jsonFieldsNameOfBrowseRequestPayload[fieldIdx] } else { name = strconv.Itoa(fieldIdx) } failures = append(failures, validate.FieldError{ Name: name, Error: validate.ErrFieldRequired, }) // Reset bit. result &^= 1 << bitIdx } } } if len(failures) > 0 { return &validate.Error{Fields: failures} } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *BrowseRequestPayload) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *BrowseRequestPayload) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. func (s *BrowseResponsePayload) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *BrowseResponsePayload) encodeFields(e *jx.Encoder) { { e.FieldStart("responseContext") s.ResponseContext.Encode(e) } { e.FieldStart("header") s.Header.Encode(e) } { e.FieldStart("contents") s.Contents.Encode(e) } { if s.TrackingParams.Set { e.FieldStart("trackingParams") s.TrackingParams.Encode(e) } } } var jsonFieldsNameOfBrowseResponsePayload = [4]string{ 0: "responseContext", 1: "header", 2: "contents", 3: "trackingParams", } // Decode decodes BrowseResponsePayload from json. func (s *BrowseResponsePayload) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode BrowseResponsePayload to nil") } var requiredBitSet [1]uint8 if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "responseContext": requiredBitSet[0] |= 1 << 0 if err := func() error { if err := s.ResponseContext.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"responseContext\"") } case "header": requiredBitSet[0] |= 1 << 1 if err := func() error { if err := s.Header.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"header\"") } case "contents": requiredBitSet[0] |= 1 << 2 if err := func() error { if err := s.Contents.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"contents\"") } case "trackingParams": if err := func() error { s.TrackingParams.Reset() if err := s.TrackingParams.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"trackingParams\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode BrowseResponsePayload") } // Validate required fields. var failures []validate.FieldError for i, mask := range [1]uint8{ 0b00000111, } { if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { // Mask only required fields and check equality to mask using XOR. // // If XOR result is not zero, result is not equal to expected, so some fields are missed. // Bits of fields which would be set are actually bits of missed fields. missed := bits.OnesCount8(result) for bitN := 0; bitN < missed; bitN++ { bitIdx := bits.TrailingZeros8(result) fieldIdx := i*8 + bitIdx var name string if fieldIdx < len(jsonFieldsNameOfBrowseResponsePayload) { name = jsonFieldsNameOfBrowseResponsePayload[fieldIdx] } else { name = strconv.Itoa(fieldIdx) } failures = append(failures, validate.FieldError{ Name: name, Error: validate.ErrFieldRequired, }) // Reset bit. result &^= 1 << bitIdx } } } if len(failures) > 0 { return &validate.Error{Fields: failures} } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *BrowseResponsePayload) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *BrowseResponsePayload) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. func (s *BrowseResponsePayloadContents) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *BrowseResponsePayloadContents) encodeFields(e *jx.Encoder) { { if s.KidsHomeScreenRenderer.Set { e.FieldStart("kidsHomeScreenRenderer") s.KidsHomeScreenRenderer.Encode(e) } } } var jsonFieldsNameOfBrowseResponsePayloadContents = [1]string{ 0: "kidsHomeScreenRenderer", } // Decode decodes BrowseResponsePayloadContents from json. func (s *BrowseResponsePayloadContents) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode BrowseResponsePayloadContents to nil") } if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "kidsHomeScreenRenderer": if err := func() error { s.KidsHomeScreenRenderer.Reset() if err := s.KidsHomeScreenRenderer.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"kidsHomeScreenRenderer\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode BrowseResponsePayloadContents") } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *BrowseResponsePayloadContents) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *BrowseResponsePayloadContents) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. func (s *BrowseResponsePayloadHeader) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *BrowseResponsePayloadHeader) encodeFields(e *jx.Encoder) { { if s.KidsCategoriesHeaderRenderer.Set { e.FieldStart("kidsCategoriesHeaderRenderer") s.KidsCategoriesHeaderRenderer.Encode(e) } } } var jsonFieldsNameOfBrowseResponsePayloadHeader = [1]string{ 0: "kidsCategoriesHeaderRenderer", } // Decode decodes BrowseResponsePayloadHeader from json. func (s *BrowseResponsePayloadHeader) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode BrowseResponsePayloadHeader to nil") } if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "kidsCategoriesHeaderRenderer": if err := func() error { s.KidsCategoriesHeaderRenderer.Reset() if err := s.KidsCategoriesHeaderRenderer.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"kidsCategoriesHeaderRenderer\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode BrowseResponsePayloadHeader") } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *BrowseResponsePayloadHeader) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *BrowseResponsePayloadHeader) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. func (s *CategoriesHeaderRenderer) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *CategoriesHeaderRenderer) encodeFields(e *jx.Encoder) { { if s.TrackingParams.Set { e.FieldStart("trackingParams") s.TrackingParams.Encode(e) } } } var jsonFieldsNameOfCategoriesHeaderRenderer = [1]string{ 0: "trackingParams", } // Decode decodes CategoriesHeaderRenderer from json. func (s *CategoriesHeaderRenderer) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode CategoriesHeaderRenderer to nil") } if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "trackingParams": if err := func() error { s.TrackingParams.Reset() if err := s.TrackingParams.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"trackingParams\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode CategoriesHeaderRenderer") } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *CategoriesHeaderRenderer) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *CategoriesHeaderRenderer) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. func (s *CategoryAssets) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *CategoryAssets) encodeFields(e *jx.Encoder) { { e.FieldStart("assetKey") e.Str(s.AssetKey) } { if s.BackgroundColor.Set { e.FieldStart("backgroundColor") s.BackgroundColor.Encode(e) } } } var jsonFieldsNameOfCategoryAssets = [2]string{ 0: "assetKey", 1: "backgroundColor", } // Decode decodes CategoryAssets from json. func (s *CategoryAssets) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode CategoryAssets to nil") } var requiredBitSet [1]uint8 if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "assetKey": requiredBitSet[0] |= 1 << 0 if err := func() error { v, err := d.Str() s.AssetKey = string(v) if err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"assetKey\"") } case "backgroundColor": if err := func() error { s.BackgroundColor.Reset() if err := s.BackgroundColor.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"backgroundColor\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode CategoryAssets") } // Validate required fields. var failures []validate.FieldError for i, mask := range [1]uint8{ 0b00000001, } { if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { // Mask only required fields and check equality to mask using XOR. // // If XOR result is not zero, result is not equal to expected, so some fields are missed. // Bits of fields which would be set are actually bits of missed fields. missed := bits.OnesCount8(result) for bitN := 0; bitN < missed; bitN++ { bitIdx := bits.TrailingZeros8(result) fieldIdx := i*8 + bitIdx var name string if fieldIdx < len(jsonFieldsNameOfCategoryAssets) { name = jsonFieldsNameOfCategoryAssets[fieldIdx] } else { name = strconv.Itoa(fieldIdx) } failures = append(failures, validate.FieldError{ Name: name, Error: validate.ErrFieldRequired, }) // Reset bit. result &^= 1 << bitIdx } } } if len(failures) > 0 { return &validate.Error{Fields: failures} } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *CategoryAssets) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *CategoryAssets) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. func (s *CompactChannelRenderer) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *CompactChannelRenderer) encodeFields(e *jx.Encoder) { { e.FieldStart("channelId") e.Str(s.ChannelId) } { if s.Thumbnail.Set { e.FieldStart("thumbnail") s.Thumbnail.Encode(e) } } { e.FieldStart("displayName") s.DisplayName.Encode(e) } { e.FieldStart("videoCountText") s.VideoCountText.Encode(e) } { if s.SubscriberCountText.Set { e.FieldStart("subscriberCountText") s.SubscriberCountText.Encode(e) } } { if s.NavigationEndpoint.Set { e.FieldStart("navigationEndpoint") s.NavigationEndpoint.Encode(e) } } { e.FieldStart("title") s.Title.Encode(e) } { e.FieldStart("trackingParams") e.Str(s.TrackingParams) } } var jsonFieldsNameOfCompactChannelRenderer = [8]string{ 0: "channelId", 1: "thumbnail", 2: "displayName", 3: "videoCountText", 4: "subscriberCountText", 5: "navigationEndpoint", 6: "title", 7: "trackingParams", } // Decode decodes CompactChannelRenderer from json. func (s *CompactChannelRenderer) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode CompactChannelRenderer to nil") } var requiredBitSet [1]uint8 if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "channelId": requiredBitSet[0] |= 1 << 0 if err := func() error { v, err := d.Str() s.ChannelId = string(v) if err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"channelId\"") } case "thumbnail": if err := func() error { s.Thumbnail.Reset() if err := s.Thumbnail.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"thumbnail\"") } case "displayName": requiredBitSet[0] |= 1 << 2 if err := func() error { if err := s.DisplayName.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"displayName\"") } case "videoCountText": requiredBitSet[0] |= 1 << 3 if err := func() error { if err := s.VideoCountText.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"videoCountText\"") } case "subscriberCountText": if err := func() error { s.SubscriberCountText.Reset() if err := s.SubscriberCountText.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"subscriberCountText\"") } case "navigationEndpoint": if err := func() error { s.NavigationEndpoint.Reset() if err := s.NavigationEndpoint.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"navigationEndpoint\"") } case "title": requiredBitSet[0] |= 1 << 6 if err := func() error { if err := s.Title.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"title\"") } case "trackingParams": requiredBitSet[0] |= 1 << 7 if err := func() error { v, err := d.Str() s.TrackingParams = string(v) if err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"trackingParams\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode CompactChannelRenderer") } // Validate required fields. var failures []validate.FieldError for i, mask := range [1]uint8{ 0b11001101, } { if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { // Mask only required fields and check equality to mask using XOR. // // If XOR result is not zero, result is not equal to expected, so some fields are missed. // Bits of fields which would be set are actually bits of missed fields. missed := bits.OnesCount8(result) for bitN := 0; bitN < missed; bitN++ { bitIdx := bits.TrailingZeros8(result) fieldIdx := i*8 + bitIdx var name string if fieldIdx < len(jsonFieldsNameOfCompactChannelRenderer) { name = jsonFieldsNameOfCompactChannelRenderer[fieldIdx] } else { name = strconv.Itoa(fieldIdx) } failures = append(failures, validate.FieldError{ Name: name, Error: validate.ErrFieldRequired, }) // Reset bit. result &^= 1 << bitIdx } } } if len(failures) > 0 { return &validate.Error{Fields: failures} } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *CompactChannelRenderer) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *CompactChannelRenderer) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. func (s *CompactChannelRendererThumbnail) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *CompactChannelRendererThumbnail) encodeFields(e *jx.Encoder) { { if s.Thumbnails != nil { e.FieldStart("thumbnails") e.ArrStart() for _, elem := range s.Thumbnails { elem.Encode(e) } e.ArrEnd() } } } var jsonFieldsNameOfCompactChannelRendererThumbnail = [1]string{ 0: "thumbnails", } // Decode decodes CompactChannelRendererThumbnail from json. func (s *CompactChannelRendererThumbnail) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode CompactChannelRendererThumbnail to nil") } if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "thumbnails": if err := func() error { s.Thumbnails = make([]Thumbnail, 0) if err := d.Arr(func(d *jx.Decoder) error { var elem Thumbnail if err := elem.Decode(d); err != nil { return err } s.Thumbnails = append(s.Thumbnails, elem) return nil }); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"thumbnails\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode CompactChannelRendererThumbnail") } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *CompactChannelRendererThumbnail) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *CompactChannelRendererThumbnail) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. func (s *CompactPlaylistRenderer) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *CompactPlaylistRenderer) encodeFields(e *jx.Encoder) { { e.FieldStart("playlistId") e.Str(s.PlaylistId) } { if s.Thumbnail.Set { e.FieldStart("thumbnail") s.Thumbnail.Encode(e) } } { e.FieldStart("title") s.Title.Encode(e) } { if s.ShortBylineText.Set { e.FieldStart("shortBylineText") s.ShortBylineText.Encode(e) } } { if s.VideoCountText.Set { e.FieldStart("videoCountText") s.VideoCountText.Encode(e) } } { if s.NavigationEndpoint.Set { e.FieldStart("navigationEndpoint") s.NavigationEndpoint.Encode(e) } } { if s.VideoCountShortText.Set { e.FieldStart("videoCountShortText") s.VideoCountShortText.Encode(e) } } { e.FieldStart("trackingParams") e.Str(s.TrackingParams) } { if s.SidebarThumbnails != nil { e.FieldStart("sidebarThumbnails") e.ArrStart() for _, elem := range s.SidebarThumbnails { elem.Encode(e) } e.ArrEnd() } } { if s.ThumbnailText.Set { e.FieldStart("thumbnailText") s.ThumbnailText.Encode(e) } } { if s.ShareUrl.Set { e.FieldStart("shareUrl") s.ShareUrl.Encode(e) } } { if s.LongBylineText.Set { e.FieldStart("longBylineText") s.LongBylineText.Encode(e) } } { if s.TvBanner.Set { e.FieldStart("tvBanner") s.TvBanner.Encode(e) } } } var jsonFieldsNameOfCompactPlaylistRenderer = [13]string{ 0: "playlistId", 1: "thumbnail", 2: "title", 3: "shortBylineText", 4: "videoCountText", 5: "navigationEndpoint", 6: "videoCountShortText", 7: "trackingParams", 8: "sidebarThumbnails", 9: "thumbnailText", 10: "shareUrl", 11: "longBylineText", 12: "tvBanner", } // Decode decodes CompactPlaylistRenderer from json. func (s *CompactPlaylistRenderer) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode CompactPlaylistRenderer to nil") } var requiredBitSet [2]uint8 if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "playlistId": requiredBitSet[0] |= 1 << 0 if err := func() error { v, err := d.Str() s.PlaylistId = string(v) if err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"playlistId\"") } case "thumbnail": if err := func() error { s.Thumbnail.Reset() if err := s.Thumbnail.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"thumbnail\"") } case "title": requiredBitSet[0] |= 1 << 2 if err := func() error { if err := s.Title.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"title\"") } case "shortBylineText": if err := func() error { s.ShortBylineText.Reset() if err := s.ShortBylineText.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"shortBylineText\"") } case "videoCountText": if err := func() error { s.VideoCountText.Reset() if err := s.VideoCountText.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"videoCountText\"") } case "navigationEndpoint": if err := func() error { s.NavigationEndpoint.Reset() if err := s.NavigationEndpoint.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"navigationEndpoint\"") } case "videoCountShortText": if err := func() error { s.VideoCountShortText.Reset() if err := s.VideoCountShortText.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"videoCountShortText\"") } case "trackingParams": requiredBitSet[0] |= 1 << 7 if err := func() error { v, err := d.Str() s.TrackingParams = string(v) if err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"trackingParams\"") } case "sidebarThumbnails": if err := func() error { s.SidebarThumbnails = make([]CompactPlaylistRendererSidebarThumbnailsItem, 0) if err := d.Arr(func(d *jx.Decoder) error { var elem CompactPlaylistRendererSidebarThumbnailsItem if err := elem.Decode(d); err != nil { return err } s.SidebarThumbnails = append(s.SidebarThumbnails, elem) return nil }); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"sidebarThumbnails\"") } case "thumbnailText": if err := func() error { s.ThumbnailText.Reset() if err := s.ThumbnailText.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"thumbnailText\"") } case "shareUrl": if err := func() error { s.ShareUrl.Reset() if err := s.ShareUrl.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"shareUrl\"") } case "longBylineText": if err := func() error { s.LongBylineText.Reset() if err := s.LongBylineText.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"longBylineText\"") } case "tvBanner": if err := func() error { s.TvBanner.Reset() if err := s.TvBanner.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"tvBanner\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode CompactPlaylistRenderer") } // Validate required fields. var failures []validate.FieldError for i, mask := range [2]uint8{ 0b10000101, 0b00000000, } { if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { // Mask only required fields and check equality to mask using XOR. // // If XOR result is not zero, result is not equal to expected, so some fields are missed. // Bits of fields which would be set are actually bits of missed fields. missed := bits.OnesCount8(result) for bitN := 0; bitN < missed; bitN++ { bitIdx := bits.TrailingZeros8(result) fieldIdx := i*8 + bitIdx var name string if fieldIdx < len(jsonFieldsNameOfCompactPlaylistRenderer) { name = jsonFieldsNameOfCompactPlaylistRenderer[fieldIdx] } else { name = strconv.Itoa(fieldIdx) } failures = append(failures, validate.FieldError{ Name: name, Error: validate.ErrFieldRequired, }) // Reset bit. result &^= 1 << bitIdx } } } if len(failures) > 0 { return &validate.Error{Fields: failures} } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *CompactPlaylistRenderer) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *CompactPlaylistRenderer) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. func (s *CompactPlaylistRendererSidebarThumbnailsItem) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *CompactPlaylistRendererSidebarThumbnailsItem) encodeFields(e *jx.Encoder) { { if s.Thumbnails != nil { e.FieldStart("thumbnails") e.ArrStart() for _, elem := range s.Thumbnails { elem.Encode(e) } e.ArrEnd() } } } var jsonFieldsNameOfCompactPlaylistRendererSidebarThumbnailsItem = [1]string{ 0: "thumbnails", } // Decode decodes CompactPlaylistRendererSidebarThumbnailsItem from json. func (s *CompactPlaylistRendererSidebarThumbnailsItem) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode CompactPlaylistRendererSidebarThumbnailsItem to nil") } if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "thumbnails": if err := func() error { s.Thumbnails = make([]Thumbnail, 0) if err := d.Arr(func(d *jx.Decoder) error { var elem Thumbnail if err := elem.Decode(d); err != nil { return err } s.Thumbnails = append(s.Thumbnails, elem) return nil }); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"thumbnails\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode CompactPlaylistRendererSidebarThumbnailsItem") } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *CompactPlaylistRendererSidebarThumbnailsItem) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *CompactPlaylistRendererSidebarThumbnailsItem) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. func (s *CompactPlaylistRendererThumbnail) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *CompactPlaylistRendererThumbnail) encodeFields(e *jx.Encoder) { { if s.Thumbnails != nil { e.FieldStart("thumbnails") e.ArrStart() for _, elem := range s.Thumbnails { elem.Encode(e) } e.ArrEnd() } } } var jsonFieldsNameOfCompactPlaylistRendererThumbnail = [1]string{ 0: "thumbnails", } // Decode decodes CompactPlaylistRendererThumbnail from json. func (s *CompactPlaylistRendererThumbnail) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode CompactPlaylistRendererThumbnail to nil") } if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "thumbnails": if err := func() error { s.Thumbnails = make([]Thumbnail, 0) if err := d.Arr(func(d *jx.Decoder) error { var elem Thumbnail if err := elem.Decode(d); err != nil { return err } s.Thumbnails = append(s.Thumbnails, elem) return nil }); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"thumbnails\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode CompactPlaylistRendererThumbnail") } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *CompactPlaylistRendererThumbnail) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *CompactPlaylistRendererThumbnail) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. func (s *CompactPlaylistRendererTvBanner) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *CompactPlaylistRendererTvBanner) encodeFields(e *jx.Encoder) { { if s.Thumbnails != nil { e.FieldStart("thumbnails") e.ArrStart() for _, elem := range s.Thumbnails { elem.Encode(e) } e.ArrEnd() } } } var jsonFieldsNameOfCompactPlaylistRendererTvBanner = [1]string{ 0: "thumbnails", } // Decode decodes CompactPlaylistRendererTvBanner from json. func (s *CompactPlaylistRendererTvBanner) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode CompactPlaylistRendererTvBanner to nil") } if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "thumbnails": if err := func() error { s.Thumbnails = make([]Thumbnail, 0) if err := d.Arr(func(d *jx.Decoder) error { var elem Thumbnail if err := elem.Decode(d); err != nil { return err } s.Thumbnails = append(s.Thumbnails, elem) return nil }); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"thumbnails\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode CompactPlaylistRendererTvBanner") } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *CompactPlaylistRendererTvBanner) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *CompactPlaylistRendererTvBanner) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. func (s *CompactVideoRenderer) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *CompactVideoRenderer) encodeFields(e *jx.Encoder) { { e.FieldStart("videoId") e.Str(s.VideoId) } { if s.Thumbnail.Set { e.FieldStart("thumbnail") s.Thumbnail.Encode(e) } } { e.FieldStart("title") s.Title.Encode(e) } { if s.LongBylineText.Set { e.FieldStart("longBylineText") s.LongBylineText.Encode(e) } } { if s.PublishedTimeText.Set { e.FieldStart("publishedTimeText") s.PublishedTimeText.Encode(e) } } { e.FieldStart("viewCountText") s.ViewCountText.Encode(e) } { if s.LengthText.Set { e.FieldStart("lengthText") s.LengthText.Encode(e) } } { if s.NavigationEndpoint.Set { e.FieldStart("navigationEndpoint") s.NavigationEndpoint.Encode(e) } } { if s.ShortBylineText.Set { e.FieldStart("shortBylineText") s.ShortBylineText.Encode(e) } } { if s.ChannelThumbnail.Set { e.FieldStart("channelThumbnail") s.ChannelThumbnail.Encode(e) } } { e.FieldStart("trackingParams") e.Str(s.TrackingParams) } { if s.ShortViewCountText.Set { e.FieldStart("shortViewCountText") s.ShortViewCountText.Encode(e) } } { if s.Accessibility.Set { e.FieldStart("accessibility") s.Accessibility.Encode(e) } } { e.FieldStart("kidsVideoOwnerExtension") s.KidsVideoOwnerExtension.Encode(e) } } var jsonFieldsNameOfCompactVideoRenderer = [14]string{ 0: "videoId", 1: "thumbnail", 2: "title", 3: "longBylineText", 4: "publishedTimeText", 5: "viewCountText", 6: "lengthText", 7: "navigationEndpoint", 8: "shortBylineText", 9: "channelThumbnail", 10: "trackingParams", 11: "shortViewCountText", 12: "accessibility", 13: "kidsVideoOwnerExtension", } // Decode decodes CompactVideoRenderer from json. func (s *CompactVideoRenderer) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode CompactVideoRenderer to nil") } var requiredBitSet [2]uint8 if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "videoId": requiredBitSet[0] |= 1 << 0 if err := func() error { v, err := d.Str() s.VideoId = string(v) if err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"videoId\"") } case "thumbnail": if err := func() error { s.Thumbnail.Reset() if err := s.Thumbnail.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"thumbnail\"") } case "title": requiredBitSet[0] |= 1 << 2 if err := func() error { if err := s.Title.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"title\"") } case "longBylineText": if err := func() error { s.LongBylineText.Reset() if err := s.LongBylineText.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"longBylineText\"") } case "publishedTimeText": if err := func() error { s.PublishedTimeText.Reset() if err := s.PublishedTimeText.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"publishedTimeText\"") } case "viewCountText": requiredBitSet[0] |= 1 << 5 if err := func() error { if err := s.ViewCountText.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"viewCountText\"") } case "lengthText": if err := func() error { s.LengthText.Reset() if err := s.LengthText.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"lengthText\"") } case "navigationEndpoint": if err := func() error { s.NavigationEndpoint.Reset() if err := s.NavigationEndpoint.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"navigationEndpoint\"") } case "shortBylineText": if err := func() error { s.ShortBylineText.Reset() if err := s.ShortBylineText.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"shortBylineText\"") } case "channelThumbnail": if err := func() error { s.ChannelThumbnail.Reset() if err := s.ChannelThumbnail.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"channelThumbnail\"") } case "trackingParams": requiredBitSet[1] |= 1 << 2 if err := func() error { v, err := d.Str() s.TrackingParams = string(v) if err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"trackingParams\"") } case "shortViewCountText": if err := func() error { s.ShortViewCountText.Reset() if err := s.ShortViewCountText.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"shortViewCountText\"") } case "accessibility": if err := func() error { s.Accessibility.Reset() if err := s.Accessibility.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"accessibility\"") } case "kidsVideoOwnerExtension": requiredBitSet[1] |= 1 << 5 if err := func() error { if err := s.KidsVideoOwnerExtension.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"kidsVideoOwnerExtension\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode CompactVideoRenderer") } // Validate required fields. var failures []validate.FieldError for i, mask := range [2]uint8{ 0b00100101, 0b00100100, } { if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { // Mask only required fields and check equality to mask using XOR. // // If XOR result is not zero, result is not equal to expected, so some fields are missed. // Bits of fields which would be set are actually bits of missed fields. missed := bits.OnesCount8(result) for bitN := 0; bitN < missed; bitN++ { bitIdx := bits.TrailingZeros8(result) fieldIdx := i*8 + bitIdx var name string if fieldIdx < len(jsonFieldsNameOfCompactVideoRenderer) { name = jsonFieldsNameOfCompactVideoRenderer[fieldIdx] } else { name = strconv.Itoa(fieldIdx) } failures = append(failures, validate.FieldError{ Name: name, Error: validate.ErrFieldRequired, }) // Reset bit. result &^= 1 << bitIdx } } } if len(failures) > 0 { return &validate.Error{Fields: failures} } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *CompactVideoRenderer) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *CompactVideoRenderer) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. func (s *CompactVideoRendererChannelThumbnail) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *CompactVideoRendererChannelThumbnail) encodeFields(e *jx.Encoder) { { if s.Thumbnails != nil { e.FieldStart("thumbnails") e.ArrStart() for _, elem := range s.Thumbnails { elem.Encode(e) } e.ArrEnd() } } } var jsonFieldsNameOfCompactVideoRendererChannelThumbnail = [1]string{ 0: "thumbnails", } // Decode decodes CompactVideoRendererChannelThumbnail from json. func (s *CompactVideoRendererChannelThumbnail) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode CompactVideoRendererChannelThumbnail to nil") } if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "thumbnails": if err := func() error { s.Thumbnails = make([]Thumbnail, 0) if err := d.Arr(func(d *jx.Decoder) error { var elem Thumbnail if err := elem.Decode(d); err != nil { return err } s.Thumbnails = append(s.Thumbnails, elem) return nil }); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"thumbnails\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode CompactVideoRendererChannelThumbnail") } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *CompactVideoRendererChannelThumbnail) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *CompactVideoRendererChannelThumbnail) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. func (s *CompactVideoRendererThumbnail) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *CompactVideoRendererThumbnail) encodeFields(e *jx.Encoder) { { if s.Thumbnails != nil { e.FieldStart("thumbnails") e.ArrStart() for _, elem := range s.Thumbnails { elem.Encode(e) } e.ArrEnd() } } } var jsonFieldsNameOfCompactVideoRendererThumbnail = [1]string{ 0: "thumbnails", } // Decode decodes CompactVideoRendererThumbnail from json. func (s *CompactVideoRendererThumbnail) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode CompactVideoRendererThumbnail to nil") } if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "thumbnails": if err := func() error { s.Thumbnails = make([]Thumbnail, 0) if err := d.Arr(func(d *jx.Decoder) error { var elem Thumbnail if err := elem.Decode(d); err != nil { return err } s.Thumbnails = append(s.Thumbnails, elem) return nil }); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"thumbnails\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode CompactVideoRendererThumbnail") } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *CompactVideoRendererThumbnail) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *CompactVideoRendererThumbnail) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. func (s *Error) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *Error) encodeFields(e *jx.Encoder) { { e.FieldStart("message") e.Str(s.Message) } { if s.Domain.Set { e.FieldStart("domain") s.Domain.Encode(e) } } { if s.Reason.Set { e.FieldStart("reason") s.Reason.Encode(e) } } } var jsonFieldsNameOfError = [3]string{ 0: "message", 1: "domain", 2: "reason", } // Decode decodes Error from json. func (s *Error) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode Error to nil") } var requiredBitSet [1]uint8 if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "message": requiredBitSet[0] |= 1 << 0 if err := func() error { v, err := d.Str() s.Message = string(v) if err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"message\"") } case "domain": if err := func() error { s.Domain.Reset() if err := s.Domain.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"domain\"") } case "reason": if err := func() error { s.Reason.Reset() if err := s.Reason.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"reason\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode Error") } // Validate required fields. var failures []validate.FieldError for i, mask := range [1]uint8{ 0b00000001, } { if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { // Mask only required fields and check equality to mask using XOR. // // If XOR result is not zero, result is not equal to expected, so some fields are missed. // Bits of fields which would be set are actually bits of missed fields. missed := bits.OnesCount8(result) for bitN := 0; bitN < missed; bitN++ { bitIdx := bits.TrailingZeros8(result) fieldIdx := i*8 + bitIdx var name string if fieldIdx < len(jsonFieldsNameOfError) { name = jsonFieldsNameOfError[fieldIdx] } else { name = strconv.Itoa(fieldIdx) } failures = append(failures, validate.FieldError{ Name: name, Error: validate.ErrFieldRequired, }) // Reset bit. result &^= 1 << bitIdx } } } if len(failures) > 0 { return &validate.Error{Fields: failures} } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *Error) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *Error) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. func (s *ErrorResponsePayload) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *ErrorResponsePayload) encodeFields(e *jx.Encoder) { { e.FieldStart("error") s.Error.Encode(e) } } var jsonFieldsNameOfErrorResponsePayload = [1]string{ 0: "error", } // Decode decodes ErrorResponsePayload from json. func (s *ErrorResponsePayload) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode ErrorResponsePayload to nil") } var requiredBitSet [1]uint8 if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "error": requiredBitSet[0] |= 1 << 0 if err := func() error { if err := s.Error.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"error\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode ErrorResponsePayload") } // Validate required fields. var failures []validate.FieldError for i, mask := range [1]uint8{ 0b00000001, } { if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { // Mask only required fields and check equality to mask using XOR. // // If XOR result is not zero, result is not equal to expected, so some fields are missed. // Bits of fields which would be set are actually bits of missed fields. missed := bits.OnesCount8(result) for bitN := 0; bitN < missed; bitN++ { bitIdx := bits.TrailingZeros8(result) fieldIdx := i*8 + bitIdx var name string if fieldIdx < len(jsonFieldsNameOfErrorResponsePayload) { name = jsonFieldsNameOfErrorResponsePayload[fieldIdx] } else { name = strconv.Itoa(fieldIdx) } failures = append(failures, validate.FieldError{ Name: name, Error: validate.ErrFieldRequired, }) // Reset bit. result &^= 1 << bitIdx } } } if len(failures) > 0 { return &validate.Error{Fields: failures} } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *ErrorResponsePayload) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *ErrorResponsePayload) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. func (s *ErrorResponsePayloadError) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *ErrorResponsePayloadError) encodeFields(e *jx.Encoder) { { e.FieldStart("code") e.Int(s.Code) } { e.FieldStart("message") e.Str(s.Message) } { if s.Errors != nil { e.FieldStart("errors") e.ArrStart() for _, elem := range s.Errors { elem.Encode(e) } e.ArrEnd() } } { e.FieldStart("status") e.Str(s.Status) } } var jsonFieldsNameOfErrorResponsePayloadError = [4]string{ 0: "code", 1: "message", 2: "errors", 3: "status", } // Decode decodes ErrorResponsePayloadError from json. func (s *ErrorResponsePayloadError) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode ErrorResponsePayloadError to nil") } var requiredBitSet [1]uint8 if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "code": requiredBitSet[0] |= 1 << 0 if err := func() error { v, err := d.Int() s.Code = int(v) if err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"code\"") } case "message": requiredBitSet[0] |= 1 << 1 if err := func() error { v, err := d.Str() s.Message = string(v) if err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"message\"") } case "errors": if err := func() error { s.Errors = make([]Error, 0) if err := d.Arr(func(d *jx.Decoder) error { var elem Error if err := elem.Decode(d); err != nil { return err } s.Errors = append(s.Errors, elem) return nil }); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"errors\"") } case "status": requiredBitSet[0] |= 1 << 3 if err := func() error { v, err := d.Str() s.Status = string(v) if err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"status\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode ErrorResponsePayloadError") } // Validate required fields. var failures []validate.FieldError for i, mask := range [1]uint8{ 0b00001011, } { if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { // Mask only required fields and check equality to mask using XOR. // // If XOR result is not zero, result is not equal to expected, so some fields are missed. // Bits of fields which would be set are actually bits of missed fields. missed := bits.OnesCount8(result) for bitN := 0; bitN < missed; bitN++ { bitIdx := bits.TrailingZeros8(result) fieldIdx := i*8 + bitIdx var name string if fieldIdx < len(jsonFieldsNameOfErrorResponsePayloadError) { name = jsonFieldsNameOfErrorResponsePayloadError[fieldIdx] } else { name = strconv.Itoa(fieldIdx) } failures = append(failures, validate.FieldError{ Name: name, Error: validate.ErrFieldRequired, }) // Reset bit. result &^= 1 << bitIdx } } } if len(failures) > 0 { return &validate.Error{Fields: failures} } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *ErrorResponsePayloadError) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *ErrorResponsePayloadError) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. func (s *ItemSectionRenderer) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *ItemSectionRenderer) encodeFields(e *jx.Encoder) { { e.FieldStart("contents") e.ArrStart() for _, elem := range s.Contents { elem.Encode(e) } e.ArrEnd() } { e.FieldStart("trackingParams") e.Str(s.TrackingParams) } } var jsonFieldsNameOfItemSectionRenderer = [2]string{ 0: "contents", 1: "trackingParams", } // Decode decodes ItemSectionRenderer from json. func (s *ItemSectionRenderer) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode ItemSectionRenderer to nil") } var requiredBitSet [1]uint8 if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "contents": requiredBitSet[0] |= 1 << 0 if err := func() error { s.Contents = make([]ItemSectionRendererContentsItem, 0) if err := d.Arr(func(d *jx.Decoder) error { var elem ItemSectionRendererContentsItem if err := elem.Decode(d); err != nil { return err } s.Contents = append(s.Contents, elem) return nil }); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"contents\"") } case "trackingParams": requiredBitSet[0] |= 1 << 1 if err := func() error { v, err := d.Str() s.TrackingParams = string(v) if err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"trackingParams\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode ItemSectionRenderer") } // Validate required fields. var failures []validate.FieldError for i, mask := range [1]uint8{ 0b00000011, } { if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { // Mask only required fields and check equality to mask using XOR. // // If XOR result is not zero, result is not equal to expected, so some fields are missed. // Bits of fields which would be set are actually bits of missed fields. missed := bits.OnesCount8(result) for bitN := 0; bitN < missed; bitN++ { bitIdx := bits.TrailingZeros8(result) fieldIdx := i*8 + bitIdx var name string if fieldIdx < len(jsonFieldsNameOfItemSectionRenderer) { name = jsonFieldsNameOfItemSectionRenderer[fieldIdx] } else { name = strconv.Itoa(fieldIdx) } failures = append(failures, validate.FieldError{ Name: name, Error: validate.ErrFieldRequired, }) // Reset bit. result &^= 1 << bitIdx } } } if len(failures) > 0 { return &validate.Error{Fields: failures} } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *ItemSectionRenderer) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *ItemSectionRenderer) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. func (s *ItemSectionRendererContentsItem) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *ItemSectionRendererContentsItem) encodeFields(e *jx.Encoder) { { if s.CompactPlaylistRenderer.Set { e.FieldStart("compactPlaylistRenderer") s.CompactPlaylistRenderer.Encode(e) } } { if s.CompactChannelRenderer.Set { e.FieldStart("compactChannelRenderer") s.CompactChannelRenderer.Encode(e) } } { if s.CompactVideoRenderer.Set { e.FieldStart("compactVideoRenderer") s.CompactVideoRenderer.Encode(e) } } } var jsonFieldsNameOfItemSectionRendererContentsItem = [3]string{ 0: "compactPlaylistRenderer", 1: "compactChannelRenderer", 2: "compactVideoRenderer", } // Decode decodes ItemSectionRendererContentsItem from json. func (s *ItemSectionRendererContentsItem) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode ItemSectionRendererContentsItem to nil") } if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "compactPlaylistRenderer": if err := func() error { s.CompactPlaylistRenderer.Reset() if err := s.CompactPlaylistRenderer.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"compactPlaylistRenderer\"") } case "compactChannelRenderer": if err := func() error { s.CompactChannelRenderer.Reset() if err := s.CompactChannelRenderer.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"compactChannelRenderer\"") } case "compactVideoRenderer": if err := func() error { s.CompactVideoRenderer.Reset() if err := s.CompactVideoRenderer.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"compactVideoRenderer\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode ItemSectionRendererContentsItem") } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *ItemSectionRendererContentsItem) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *ItemSectionRendererContentsItem) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. func (s *KeyStringValue) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *KeyStringValue) encodeFields(e *jx.Encoder) { { e.FieldStart("key") e.Str(s.Key) } { e.FieldStart("value") e.Str(s.Value) } } var jsonFieldsNameOfKeyStringValue = [2]string{ 0: "key", 1: "value", } // Decode decodes KeyStringValue from json. func (s *KeyStringValue) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode KeyStringValue to nil") } var requiredBitSet [1]uint8 if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "key": requiredBitSet[0] |= 1 << 0 if err := func() error { v, err := d.Str() s.Key = string(v) if err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"key\"") } case "value": requiredBitSet[0] |= 1 << 1 if err := func() error { v, err := d.Str() s.Value = string(v) if err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"value\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode KeyStringValue") } // Validate required fields. var failures []validate.FieldError for i, mask := range [1]uint8{ 0b00000011, } { if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { // Mask only required fields and check equality to mask using XOR. // // If XOR result is not zero, result is not equal to expected, so some fields are missed. // Bits of fields which would be set are actually bits of missed fields. missed := bits.OnesCount8(result) for bitN := 0; bitN < missed; bitN++ { bitIdx := bits.TrailingZeros8(result) fieldIdx := i*8 + bitIdx var name string if fieldIdx < len(jsonFieldsNameOfKeyStringValue) { name = jsonFieldsNameOfKeyStringValue[fieldIdx] } else { name = strconv.Itoa(fieldIdx) } failures = append(failures, validate.FieldError{ Name: name, Error: validate.ErrFieldRequired, }) // Reset bit. result &^= 1 << bitIdx } } } if len(failures) > 0 { return &validate.Error{Fields: failures} } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *KeyStringValue) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *KeyStringValue) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. func (s *KidsAppCategorySettings) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *KidsAppCategorySettings) encodeFields(e *jx.Encoder) { { if s.EnabledCategories != nil { e.FieldStart("enabledCategories") e.ArrStart() for _, elem := range s.EnabledCategories { e.Str(elem) } e.ArrEnd() } } } var jsonFieldsNameOfKidsAppCategorySettings = [1]string{ 0: "enabledCategories", } // Decode decodes KidsAppCategorySettings from json. func (s *KidsAppCategorySettings) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode KidsAppCategorySettings to nil") } if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "enabledCategories": if err := func() error { s.EnabledCategories = make([]string, 0) if err := d.Arr(func(d *jx.Decoder) error { var elem string v, err := d.Str() elem = string(v) if err != nil { return err } s.EnabledCategories = append(s.EnabledCategories, elem) return nil }); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"enabledCategories\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode KidsAppCategorySettings") } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *KidsAppCategorySettings) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *KidsAppCategorySettings) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. func (s *KidsAppContentSettings) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *KidsAppContentSettings) encodeFields(e *jx.Encoder) { { e.FieldStart("corpusPreference") s.CorpusPreference.Encode(e) } { e.FieldStart("kidsNoSearchMode") s.KidsNoSearchMode.Encode(e) } } var jsonFieldsNameOfKidsAppContentSettings = [2]string{ 0: "corpusPreference", 1: "kidsNoSearchMode", } // Decode decodes KidsAppContentSettings from json. func (s *KidsAppContentSettings) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode KidsAppContentSettings to nil") } var requiredBitSet [1]uint8 s.setDefaults() if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "corpusPreference": requiredBitSet[0] |= 1 << 0 if err := func() error { if err := s.CorpusPreference.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"corpusPreference\"") } case "kidsNoSearchMode": requiredBitSet[0] |= 1 << 1 if err := func() error { if err := s.KidsNoSearchMode.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"kidsNoSearchMode\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode KidsAppContentSettings") } // Validate required fields. var failures []validate.FieldError for i, mask := range [1]uint8{ 0b00000011, } { if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { // Mask only required fields and check equality to mask using XOR. // // If XOR result is not zero, result is not equal to expected, so some fields are missed. // Bits of fields which would be set are actually bits of missed fields. missed := bits.OnesCount8(result) for bitN := 0; bitN < missed; bitN++ { bitIdx := bits.TrailingZeros8(result) fieldIdx := i*8 + bitIdx var name string if fieldIdx < len(jsonFieldsNameOfKidsAppContentSettings) { name = jsonFieldsNameOfKidsAppContentSettings[fieldIdx] } else { name = strconv.Itoa(fieldIdx) } failures = append(failures, validate.FieldError{ Name: name, Error: validate.ErrFieldRequired, }) // Reset bit. result &^= 1 << bitIdx } } } if len(failures) > 0 { return &validate.Error{Fields: failures} } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *KidsAppContentSettings) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *KidsAppContentSettings) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode encodes KidsAppContentSettingsCorpusPreference as json. func (s KidsAppContentSettingsCorpusPreference) Encode(e *jx.Encoder) { e.Str(string(s)) } // Decode decodes KidsAppContentSettingsCorpusPreference from json. func (s *KidsAppContentSettingsCorpusPreference) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode KidsAppContentSettingsCorpusPreference to nil") } v, err := d.StrBytes() if err != nil { return err } // Try to use constant string. switch KidsAppContentSettingsCorpusPreference(v) { case KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCEUNKNOWN: *s = KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCEUNKNOWN case KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCEYOUNGER: *s = KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCEYOUNGER case KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCETWEEN: *s = KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCETWEEN case KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCEPAMYOUNGER: *s = KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCEPAMYOUNGER case KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCEPAMTWEEN: *s = KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCEPAMTWEEN case KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCEPRESCHOOL: *s = KidsAppContentSettingsCorpusPreferenceKIDSCORPUSPREFERENCEPRESCHOOL default: *s = KidsAppContentSettingsCorpusPreference(v) } return nil } // MarshalJSON implements stdjson.Marshaler. func (s KidsAppContentSettingsCorpusPreference) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *KidsAppContentSettingsCorpusPreference) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode encodes KidsAppContentSettingsKidsNoSearchMode as json. func (s KidsAppContentSettingsKidsNoSearchMode) Encode(e *jx.Encoder) { e.Str(string(s)) } // Decode decodes KidsAppContentSettingsKidsNoSearchMode from json. func (s *KidsAppContentSettingsKidsNoSearchMode) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode KidsAppContentSettingsKidsNoSearchMode to nil") } v, err := d.StrBytes() if err != nil { return err } // Try to use constant string. switch KidsAppContentSettingsKidsNoSearchMode(v) { case KidsAppContentSettingsKidsNoSearchModeYTKIDSNOSEARCHMODEUNKNOWN: *s = KidsAppContentSettingsKidsNoSearchModeYTKIDSNOSEARCHMODEUNKNOWN case KidsAppContentSettingsKidsNoSearchModeYTKIDSNOSEARCHMODEON: *s = KidsAppContentSettingsKidsNoSearchModeYTKIDSNOSEARCHMODEON case KidsAppContentSettingsKidsNoSearchModeYTKIDSNOSEARCHMODEOFF: *s = KidsAppContentSettingsKidsNoSearchModeYTKIDSNOSEARCHMODEOFF default: *s = KidsAppContentSettingsKidsNoSearchMode(v) } return nil } // MarshalJSON implements stdjson.Marshaler. func (s KidsAppContentSettingsKidsNoSearchMode) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *KidsAppContentSettingsKidsNoSearchMode) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. func (s *KidsAppInfo) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *KidsAppInfo) encodeFields(e *jx.Encoder) { { if s.ContentSettings.Set { e.FieldStart("contentSettings") s.ContentSettings.Encode(e) } } { if s.CategorySettings.Set { e.FieldStart("categorySettings") s.CategorySettings.Encode(e) } } } var jsonFieldsNameOfKidsAppInfo = [2]string{ 0: "contentSettings", 1: "categorySettings", } // Decode decodes KidsAppInfo from json. func (s *KidsAppInfo) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode KidsAppInfo to nil") } if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "contentSettings": if err := func() error { s.ContentSettings.Reset() if err := s.ContentSettings.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"contentSettings\"") } case "categorySettings": if err := func() error { s.CategorySettings.Reset() if err := s.CategorySettings.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"categorySettings\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode KidsAppInfo") } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *KidsAppInfo) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *KidsAppInfo) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. func (s *KidsVideoOwnerExtension) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *KidsVideoOwnerExtension) encodeFields(e *jx.Encoder) { { e.FieldStart("externalChannelId") e.Str(s.ExternalChannelId) } } var jsonFieldsNameOfKidsVideoOwnerExtension = [1]string{ 0: "externalChannelId", } // Decode decodes KidsVideoOwnerExtension from json. func (s *KidsVideoOwnerExtension) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode KidsVideoOwnerExtension to nil") } var requiredBitSet [1]uint8 if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "externalChannelId": requiredBitSet[0] |= 1 << 0 if err := func() error { v, err := d.Str() s.ExternalChannelId = string(v) if err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"externalChannelId\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode KidsVideoOwnerExtension") } // Validate required fields. var failures []validate.FieldError for i, mask := range [1]uint8{ 0b00000001, } { if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { // Mask only required fields and check equality to mask using XOR. // // If XOR result is not zero, result is not equal to expected, so some fields are missed. // Bits of fields which would be set are actually bits of missed fields. missed := bits.OnesCount8(result) for bitN := 0; bitN < missed; bitN++ { bitIdx := bits.TrailingZeros8(result) fieldIdx := i*8 + bitIdx var name string if fieldIdx < len(jsonFieldsNameOfKidsVideoOwnerExtension) { name = jsonFieldsNameOfKidsVideoOwnerExtension[fieldIdx] } else { name = strconv.Itoa(fieldIdx) } failures = append(failures, validate.FieldError{ Name: name, Error: validate.ErrFieldRequired, }) // Reset bit. result &^= 1 << bitIdx } } } if len(failures) > 0 { return &validate.Error{Fields: failures} } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *KidsVideoOwnerExtension) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *KidsVideoOwnerExtension) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. func (s *NavigationEndpoint) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *NavigationEndpoint) encodeFields(e *jx.Encoder) { { if s.ClickTrackingParams.Set { e.FieldStart("clickTrackingParams") s.ClickTrackingParams.Encode(e) } } { if s.WatchEndpoint.Set { e.FieldStart("watchEndpoint") s.WatchEndpoint.Encode(e) } } { if s.BrowseEndpoint.Set { e.FieldStart("browseEndpoint") s.BrowseEndpoint.Encode(e) } } } var jsonFieldsNameOfNavigationEndpoint = [3]string{ 0: "clickTrackingParams", 1: "watchEndpoint", 2: "browseEndpoint", } // Decode decodes NavigationEndpoint from json. func (s *NavigationEndpoint) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode NavigationEndpoint to nil") } if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "clickTrackingParams": if err := func() error { s.ClickTrackingParams.Reset() if err := s.ClickTrackingParams.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"clickTrackingParams\"") } case "watchEndpoint": if err := func() error { s.WatchEndpoint.Reset() if err := s.WatchEndpoint.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"watchEndpoint\"") } case "browseEndpoint": if err := func() error { s.BrowseEndpoint.Reset() if err := s.BrowseEndpoint.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"browseEndpoint\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode NavigationEndpoint") } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *NavigationEndpoint) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *NavigationEndpoint) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode encodes Accessibility as json. func (o OptAccessibility) Encode(e *jx.Encoder) { if !o.Set { return } o.Value.Encode(e) } // Decode decodes Accessibility from json. func (o *OptAccessibility) Decode(d *jx.Decoder) error { if o == nil { return errors.New("invalid: unable to decode OptAccessibility to nil") } o.Set = true if err := o.Value.Decode(d); err != nil { return err } return nil } // MarshalJSON implements stdjson.Marshaler. func (s OptAccessibility) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *OptAccessibility) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode encodes AccessibilityData as json. func (o OptAccessibilityData) Encode(e *jx.Encoder) { if !o.Set { return } o.Value.Encode(e) } // Decode decodes AccessibilityData from json. func (o *OptAccessibilityData) Decode(d *jx.Decoder) error { if o == nil { return errors.New("invalid: unable to decode OptAccessibilityData to nil") } o.Set = true if err := o.Value.Decode(d); err != nil { return err } return nil } // MarshalJSON implements stdjson.Marshaler. func (s OptAccessibilityData) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *OptAccessibilityData) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode encodes AnchoredSectionRenderer as json. func (o OptAnchoredSectionRenderer) Encode(e *jx.Encoder) { if !o.Set { return } o.Value.Encode(e) } // Decode decodes AnchoredSectionRenderer from json. func (o *OptAnchoredSectionRenderer) Decode(d *jx.Decoder) error { if o == nil { return errors.New("invalid: unable to decode OptAnchoredSectionRenderer to nil") } o.Set = true if err := o.Value.Decode(d); err != nil { return err } return nil } // MarshalJSON implements stdjson.Marshaler. func (s OptAnchoredSectionRenderer) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *OptAnchoredSectionRenderer) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode encodes AnchoredSectionRendererContent as json. func (o OptAnchoredSectionRendererContent) Encode(e *jx.Encoder) { if !o.Set { return } o.Value.Encode(e) } // Decode decodes AnchoredSectionRendererContent from json. func (o *OptAnchoredSectionRendererContent) Decode(d *jx.Decoder) error { if o == nil { return errors.New("invalid: unable to decode OptAnchoredSectionRendererContent to nil") } o.Set = true if err := o.Value.Decode(d); err != nil { return err } return nil } // MarshalJSON implements stdjson.Marshaler. func (s OptAnchoredSectionRendererContent) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *OptAnchoredSectionRendererContent) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode encodes BrowseEndpoint as json. func (o OptBrowseEndpoint) Encode(e *jx.Encoder) { if !o.Set { return } o.Value.Encode(e) } // Decode decodes BrowseEndpoint from json. func (o *OptBrowseEndpoint) Decode(d *jx.Decoder) error { if o == nil { return errors.New("invalid: unable to decode OptBrowseEndpoint to nil") } o.Set = true if err := o.Value.Decode(d); err != nil { return err } return nil } // MarshalJSON implements stdjson.Marshaler. func (s OptBrowseEndpoint) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *OptBrowseEndpoint) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode encodes CategoriesHeaderRenderer as json. func (o OptCategoriesHeaderRenderer) Encode(e *jx.Encoder) { if !o.Set { return } o.Value.Encode(e) } // Decode decodes CategoriesHeaderRenderer from json. func (o *OptCategoriesHeaderRenderer) Decode(d *jx.Decoder) error { if o == nil { return errors.New("invalid: unable to decode OptCategoriesHeaderRenderer to nil") } o.Set = true if err := o.Value.Decode(d); err != nil { return err } return nil } // MarshalJSON implements stdjson.Marshaler. func (s OptCategoriesHeaderRenderer) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *OptCategoriesHeaderRenderer) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode encodes CategoryAssets as json. func (o OptCategoryAssets) Encode(e *jx.Encoder) { if !o.Set { return } o.Value.Encode(e) } // Decode decodes CategoryAssets from json. func (o *OptCategoryAssets) Decode(d *jx.Decoder) error { if o == nil { return errors.New("invalid: unable to decode OptCategoryAssets to nil") } o.Set = true if err := o.Value.Decode(d); err != nil { return err } return nil } // MarshalJSON implements stdjson.Marshaler. func (s OptCategoryAssets) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *OptCategoryAssets) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode encodes CompactChannelRenderer as json. func (o OptCompactChannelRenderer) Encode(e *jx.Encoder) { if !o.Set { return } o.Value.Encode(e) } // Decode decodes CompactChannelRenderer from json. func (o *OptCompactChannelRenderer) Decode(d *jx.Decoder) error { if o == nil { return errors.New("invalid: unable to decode OptCompactChannelRenderer to nil") } o.Set = true if err := o.Value.Decode(d); err != nil { return err } return nil } // MarshalJSON implements stdjson.Marshaler. func (s OptCompactChannelRenderer) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *OptCompactChannelRenderer) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode encodes CompactChannelRendererThumbnail as json. func (o OptCompactChannelRendererThumbnail) Encode(e *jx.Encoder) { if !o.Set { return } o.Value.Encode(e) } // Decode decodes CompactChannelRendererThumbnail from json. func (o *OptCompactChannelRendererThumbnail) Decode(d *jx.Decoder) error { if o == nil { return errors.New("invalid: unable to decode OptCompactChannelRendererThumbnail to nil") } o.Set = true if err := o.Value.Decode(d); err != nil { return err } return nil } // MarshalJSON implements stdjson.Marshaler. func (s OptCompactChannelRendererThumbnail) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *OptCompactChannelRendererThumbnail) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode encodes CompactPlaylistRenderer as json. func (o OptCompactPlaylistRenderer) Encode(e *jx.Encoder) { if !o.Set { return } o.Value.Encode(e) } // Decode decodes CompactPlaylistRenderer from json. func (o *OptCompactPlaylistRenderer) Decode(d *jx.Decoder) error { if o == nil { return errors.New("invalid: unable to decode OptCompactPlaylistRenderer to nil") } o.Set = true if err := o.Value.Decode(d); err != nil { return err } return nil } // MarshalJSON implements stdjson.Marshaler. func (s OptCompactPlaylistRenderer) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *OptCompactPlaylistRenderer) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode encodes CompactPlaylistRendererThumbnail as json. func (o OptCompactPlaylistRendererThumbnail) Encode(e *jx.Encoder) { if !o.Set { return } o.Value.Encode(e) } // Decode decodes CompactPlaylistRendererThumbnail from json. func (o *OptCompactPlaylistRendererThumbnail) Decode(d *jx.Decoder) error { if o == nil { return errors.New("invalid: unable to decode OptCompactPlaylistRendererThumbnail to nil") } o.Set = true if err := o.Value.Decode(d); err != nil { return err } return nil } // MarshalJSON implements stdjson.Marshaler. func (s OptCompactPlaylistRendererThumbnail) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *OptCompactPlaylistRendererThumbnail) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode encodes CompactPlaylistRendererTvBanner as json. func (o OptCompactPlaylistRendererTvBanner) Encode(e *jx.Encoder) { if !o.Set { return } o.Value.Encode(e) } // Decode decodes CompactPlaylistRendererTvBanner from json. func (o *OptCompactPlaylistRendererTvBanner) Decode(d *jx.Decoder) error { if o == nil { return errors.New("invalid: unable to decode OptCompactPlaylistRendererTvBanner to nil") } o.Set = true if err := o.Value.Decode(d); err != nil { return err } return nil } // MarshalJSON implements stdjson.Marshaler. func (s OptCompactPlaylistRendererTvBanner) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *OptCompactPlaylistRendererTvBanner) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode encodes CompactVideoRenderer as json. func (o OptCompactVideoRenderer) Encode(e *jx.Encoder) { if !o.Set { return } o.Value.Encode(e) } // Decode decodes CompactVideoRenderer from json. func (o *OptCompactVideoRenderer) Decode(d *jx.Decoder) error { if o == nil { return errors.New("invalid: unable to decode OptCompactVideoRenderer to nil") } o.Set = true if err := o.Value.Decode(d); err != nil { return err } return nil } // MarshalJSON implements stdjson.Marshaler. func (s OptCompactVideoRenderer) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *OptCompactVideoRenderer) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode encodes CompactVideoRendererChannelThumbnail as json. func (o OptCompactVideoRendererChannelThumbnail) Encode(e *jx.Encoder) { if !o.Set { return } o.Value.Encode(e) } // Decode decodes CompactVideoRendererChannelThumbnail from json. func (o *OptCompactVideoRendererChannelThumbnail) Decode(d *jx.Decoder) error { if o == nil { return errors.New("invalid: unable to decode OptCompactVideoRendererChannelThumbnail to nil") } o.Set = true if err := o.Value.Decode(d); err != nil { return err } return nil } // MarshalJSON implements stdjson.Marshaler. func (s OptCompactVideoRendererChannelThumbnail) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *OptCompactVideoRendererChannelThumbnail) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode encodes CompactVideoRendererThumbnail as json. func (o OptCompactVideoRendererThumbnail) Encode(e *jx.Encoder) { if !o.Set { return } o.Value.Encode(e) } // Decode decodes CompactVideoRendererThumbnail from json. func (o *OptCompactVideoRendererThumbnail) Decode(d *jx.Decoder) error { if o == nil { return errors.New("invalid: unable to decode OptCompactVideoRendererThumbnail to nil") } o.Set = true if err := o.Value.Decode(d); err != nil { return err } return nil } // MarshalJSON implements stdjson.Marshaler. func (s OptCompactVideoRendererThumbnail) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *OptCompactVideoRendererThumbnail) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode encodes int as json. func (o OptInt) Encode(e *jx.Encoder) { if !o.Set { return } e.Int(int(o.Value)) } // Decode decodes int from json. func (o *OptInt) Decode(d *jx.Decoder) error { if o == nil { return errors.New("invalid: unable to decode OptInt to nil") } o.Set = true v, err := d.Int() if err != nil { return err } o.Value = int(v) return nil } // MarshalJSON implements stdjson.Marshaler. func (s OptInt) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *OptInt) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode encodes ItemSectionRenderer as json. func (o OptItemSectionRenderer) Encode(e *jx.Encoder) { if !o.Set { return } o.Value.Encode(e) } // Decode decodes ItemSectionRenderer from json. func (o *OptItemSectionRenderer) Decode(d *jx.Decoder) error { if o == nil { return errors.New("invalid: unable to decode OptItemSectionRenderer to nil") } o.Set = true if err := o.Value.Decode(d); err != nil { return err } return nil } // MarshalJSON implements stdjson.Marshaler. func (s OptItemSectionRenderer) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *OptItemSectionRenderer) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode encodes KidsAppCategorySettings as json. func (o OptKidsAppCategorySettings) Encode(e *jx.Encoder) { if !o.Set { return } o.Value.Encode(e) } // Decode decodes KidsAppCategorySettings from json. func (o *OptKidsAppCategorySettings) Decode(d *jx.Decoder) error { if o == nil { return errors.New("invalid: unable to decode OptKidsAppCategorySettings to nil") } o.Set = true if err := o.Value.Decode(d); err != nil { return err } return nil } // MarshalJSON implements stdjson.Marshaler. func (s OptKidsAppCategorySettings) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *OptKidsAppCategorySettings) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode encodes KidsAppContentSettings as json. func (o OptKidsAppContentSettings) Encode(e *jx.Encoder) { if !o.Set { return } o.Value.Encode(e) } // Decode decodes KidsAppContentSettings from json. func (o *OptKidsAppContentSettings) Decode(d *jx.Decoder) error { if o == nil { return errors.New("invalid: unable to decode OptKidsAppContentSettings to nil") } o.Set = true if err := o.Value.Decode(d); err != nil { return err } return nil } // MarshalJSON implements stdjson.Marshaler. func (s OptKidsAppContentSettings) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *OptKidsAppContentSettings) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode encodes NavigationEndpoint as json. func (o OptNavigationEndpoint) Encode(e *jx.Encoder) { if !o.Set { return } o.Value.Encode(e) } // Decode decodes NavigationEndpoint from json. func (o *OptNavigationEndpoint) Decode(d *jx.Decoder) error { if o == nil { return errors.New("invalid: unable to decode OptNavigationEndpoint to nil") } o.Set = true if err := o.Value.Decode(d); err != nil { return err } return nil } // MarshalJSON implements stdjson.Marshaler. func (s OptNavigationEndpoint) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *OptNavigationEndpoint) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode encodes ScreenRenderer as json. func (o OptScreenRenderer) Encode(e *jx.Encoder) { if !o.Set { return } o.Value.Encode(e) } // Decode decodes ScreenRenderer from json. func (o *OptScreenRenderer) Decode(d *jx.Decoder) error { if o == nil { return errors.New("invalid: unable to decode OptScreenRenderer to nil") } o.Set = true if err := o.Value.Decode(d); err != nil { return err } return nil } // MarshalJSON implements stdjson.Marshaler. func (s OptScreenRenderer) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *OptScreenRenderer) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode encodes SectionListRenderer as json. func (o OptSectionListRenderer) Encode(e *jx.Encoder) { if !o.Set { return } o.Value.Encode(e) } // Decode decodes SectionListRenderer from json. func (o *OptSectionListRenderer) Decode(d *jx.Decoder) error { if o == nil { return errors.New("invalid: unable to decode OptSectionListRenderer to nil") } o.Set = true if err := o.Value.Decode(d); err != nil { return err } return nil } // MarshalJSON implements stdjson.Marshaler. func (s OptSectionListRenderer) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *OptSectionListRenderer) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode encodes string as json. func (o OptString) Encode(e *jx.Encoder) { if !o.Set { return } e.Str(string(o.Value)) } // Decode decodes string from json. func (o *OptString) Decode(d *jx.Decoder) error { if o == nil { return errors.New("invalid: unable to decode OptString to nil") } o.Set = true v, err := d.Str() if err != nil { return err } o.Value = string(v) return nil } // MarshalJSON implements stdjson.Marshaler. func (s OptString) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *OptString) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode encodes Text as json. func (o OptText) Encode(e *jx.Encoder) { if !o.Set { return } o.Value.Encode(e) } // Decode decodes Text from json. func (o *OptText) Decode(d *jx.Decoder) error { if o == nil { return errors.New("invalid: unable to decode OptText to nil") } o.Set = true if err := o.Value.Decode(d); err != nil { return err } return nil } // MarshalJSON implements stdjson.Marshaler. func (s OptText) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *OptText) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode encodes WatchEndpoint as json. func (o OptWatchEndpoint) Encode(e *jx.Encoder) { if !o.Set { return } o.Value.Encode(e) } // Decode decodes WatchEndpoint from json. func (o *OptWatchEndpoint) Decode(d *jx.Decoder) error { if o == nil { return errors.New("invalid: unable to decode OptWatchEndpoint to nil") } o.Set = true if err := o.Value.Decode(d); err != nil { return err } return nil } // MarshalJSON implements stdjson.Marshaler. func (s OptWatchEndpoint) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *OptWatchEndpoint) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. func (s *RequestClient) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *RequestClient) encodeFields(e *jx.Encoder) { { if s.ClientName.Set { e.FieldStart("clientName") s.ClientName.Encode(e) } } { if s.ClientVersion.Set { e.FieldStart("clientVersion") s.ClientVersion.Encode(e) } } { if s.Hl.Set { e.FieldStart("hl") s.Hl.Encode(e) } } { if s.Gl.Set { e.FieldStart("gl") s.Gl.Encode(e) } } { if s.ExperimentsToken.Set { e.FieldStart("experimentsToken") s.ExperimentsToken.Encode(e) } } { if s.BrowserName.Set { e.FieldStart("browserName") s.BrowserName.Encode(e) } } { if s.DeviceMake.Set { e.FieldStart("deviceMake") s.DeviceMake.Encode(e) } } { if s.BrowserVersion.Set { e.FieldStart("browserVersion") s.BrowserVersion.Encode(e) } } { if s.OsName.Set { e.FieldStart("osName") s.OsName.Encode(e) } } { if s.OsVersion.Set { e.FieldStart("osVersion") s.OsVersion.Encode(e) } } { if s.Platform.Set { e.FieldStart("platform") s.Platform.Encode(e) } } { e.FieldStart("kidsAppInfo") s.KidsAppInfo.Encode(e) } } var jsonFieldsNameOfRequestClient = [12]string{ 0: "clientName", 1: "clientVersion", 2: "hl", 3: "gl", 4: "experimentsToken", 5: "browserName", 6: "deviceMake", 7: "browserVersion", 8: "osName", 9: "osVersion", 10: "platform", 11: "kidsAppInfo", } // Decode decodes RequestClient from json. func (s *RequestClient) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode RequestClient to nil") } var requiredBitSet [2]uint8 s.setDefaults() if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "clientName": if err := func() error { s.ClientName.Reset() if err := s.ClientName.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"clientName\"") } case "clientVersion": if err := func() error { s.ClientVersion.Reset() if err := s.ClientVersion.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"clientVersion\"") } case "hl": if err := func() error { s.Hl.Reset() if err := s.Hl.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"hl\"") } case "gl": if err := func() error { s.Gl.Reset() if err := s.Gl.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"gl\"") } case "experimentsToken": if err := func() error { s.ExperimentsToken.Reset() if err := s.ExperimentsToken.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"experimentsToken\"") } case "browserName": if err := func() error { s.BrowserName.Reset() if err := s.BrowserName.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"browserName\"") } case "deviceMake": if err := func() error { s.DeviceMake.Reset() if err := s.DeviceMake.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"deviceMake\"") } case "browserVersion": if err := func() error { s.BrowserVersion.Reset() if err := s.BrowserVersion.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"browserVersion\"") } case "osName": if err := func() error { s.OsName.Reset() if err := s.OsName.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"osName\"") } case "osVersion": if err := func() error { s.OsVersion.Reset() if err := s.OsVersion.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"osVersion\"") } case "platform": if err := func() error { s.Platform.Reset() if err := s.Platform.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"platform\"") } case "kidsAppInfo": requiredBitSet[1] |= 1 << 3 if err := func() error { if err := s.KidsAppInfo.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"kidsAppInfo\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode RequestClient") } // Validate required fields. var failures []validate.FieldError for i, mask := range [2]uint8{ 0b00000000, 0b00001000, } { if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { // Mask only required fields and check equality to mask using XOR. // // If XOR result is not zero, result is not equal to expected, so some fields are missed. // Bits of fields which would be set are actually bits of missed fields. missed := bits.OnesCount8(result) for bitN := 0; bitN < missed; bitN++ { bitIdx := bits.TrailingZeros8(result) fieldIdx := i*8 + bitIdx var name string if fieldIdx < len(jsonFieldsNameOfRequestClient) { name = jsonFieldsNameOfRequestClient[fieldIdx] } else { name = strconv.Itoa(fieldIdx) } failures = append(failures, validate.FieldError{ Name: name, Error: validate.ErrFieldRequired, }) // Reset bit. result &^= 1 << bitIdx } } } if len(failures) > 0 { return &validate.Error{Fields: failures} } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *RequestClient) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *RequestClient) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. func (s *RequestContext) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *RequestContext) encodeFields(e *jx.Encoder) { { e.FieldStart("client") s.Client.Encode(e) } } var jsonFieldsNameOfRequestContext = [1]string{ 0: "client", } // Decode decodes RequestContext from json. func (s *RequestContext) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode RequestContext to nil") } var requiredBitSet [1]uint8 if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "client": requiredBitSet[0] |= 1 << 0 if err := func() error { if err := s.Client.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"client\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode RequestContext") } // Validate required fields. var failures []validate.FieldError for i, mask := range [1]uint8{ 0b00000001, } { if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { // Mask only required fields and check equality to mask using XOR. // // If XOR result is not zero, result is not equal to expected, so some fields are missed. // Bits of fields which would be set are actually bits of missed fields. missed := bits.OnesCount8(result) for bitN := 0; bitN < missed; bitN++ { bitIdx := bits.TrailingZeros8(result) fieldIdx := i*8 + bitIdx var name string if fieldIdx < len(jsonFieldsNameOfRequestContext) { name = jsonFieldsNameOfRequestContext[fieldIdx] } else { name = strconv.Itoa(fieldIdx) } failures = append(failures, validate.FieldError{ Name: name, Error: validate.ErrFieldRequired, }) // Reset bit. result &^= 1 << bitIdx } } } if len(failures) > 0 { return &validate.Error{Fields: failures} } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *RequestContext) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *RequestContext) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. func (s *ResponseContext) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *ResponseContext) encodeFields(e *jx.Encoder) { { if s.VisitorData.Set { e.FieldStart("visitorData") s.VisitorData.Encode(e) } } { if s.MaxAgeSeconds.Set { e.FieldStart("maxAgeSeconds") s.MaxAgeSeconds.Encode(e) } } { if s.ServiceTrackingParams != nil { e.FieldStart("serviceTrackingParams") e.ArrStart() for _, elem := range s.ServiceTrackingParams { elem.Encode(e) } e.ArrEnd() } } } var jsonFieldsNameOfResponseContext = [3]string{ 0: "visitorData", 1: "maxAgeSeconds", 2: "serviceTrackingParams", } // Decode decodes ResponseContext from json. func (s *ResponseContext) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode ResponseContext to nil") } if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "visitorData": if err := func() error { s.VisitorData.Reset() if err := s.VisitorData.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"visitorData\"") } case "maxAgeSeconds": if err := func() error { s.MaxAgeSeconds.Reset() if err := s.MaxAgeSeconds.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"maxAgeSeconds\"") } case "serviceTrackingParams": if err := func() error { s.ServiceTrackingParams = make([]ResponseContextServiceTrackingParamsItem, 0) if err := d.Arr(func(d *jx.Decoder) error { var elem ResponseContextServiceTrackingParamsItem if err := elem.Decode(d); err != nil { return err } s.ServiceTrackingParams = append(s.ServiceTrackingParams, elem) return nil }); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"serviceTrackingParams\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode ResponseContext") } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *ResponseContext) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *ResponseContext) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. func (s *ResponseContextServiceTrackingParamsItem) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *ResponseContextServiceTrackingParamsItem) encodeFields(e *jx.Encoder) { { if s.Service.Set { e.FieldStart("service") s.Service.Encode(e) } } { if s.Params != nil { e.FieldStart("params") e.ArrStart() for _, elem := range s.Params { elem.Encode(e) } e.ArrEnd() } } } var jsonFieldsNameOfResponseContextServiceTrackingParamsItem = [2]string{ 0: "service", 1: "params", } // Decode decodes ResponseContextServiceTrackingParamsItem from json. func (s *ResponseContextServiceTrackingParamsItem) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode ResponseContextServiceTrackingParamsItem to nil") } if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "service": if err := func() error { s.Service.Reset() if err := s.Service.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"service\"") } case "params": if err := func() error { s.Params = make([]KeyStringValue, 0) if err := d.Arr(func(d *jx.Decoder) error { var elem KeyStringValue if err := elem.Decode(d); err != nil { return err } s.Params = append(s.Params, elem) return nil }); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"params\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode ResponseContextServiceTrackingParamsItem") } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *ResponseContextServiceTrackingParamsItem) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *ResponseContextServiceTrackingParamsItem) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. func (s *ScreenAnchor) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *ScreenAnchor) encodeFields(e *jx.Encoder) { { if s.AnchoredSectionRenderer.Set { e.FieldStart("anchoredSectionRenderer") s.AnchoredSectionRenderer.Encode(e) } } } var jsonFieldsNameOfScreenAnchor = [1]string{ 0: "anchoredSectionRenderer", } // Decode decodes ScreenAnchor from json. func (s *ScreenAnchor) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode ScreenAnchor to nil") } if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "anchoredSectionRenderer": if err := func() error { s.AnchoredSectionRenderer.Reset() if err := s.AnchoredSectionRenderer.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"anchoredSectionRenderer\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode ScreenAnchor") } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *ScreenAnchor) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *ScreenAnchor) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. func (s *ScreenRenderer) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *ScreenRenderer) encodeFields(e *jx.Encoder) { { if s.Anchors != nil { e.FieldStart("anchors") e.ArrStart() for _, elem := range s.Anchors { elem.Encode(e) } e.ArrEnd() } } } var jsonFieldsNameOfScreenRenderer = [1]string{ 0: "anchors", } // Decode decodes ScreenRenderer from json. func (s *ScreenRenderer) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode ScreenRenderer to nil") } if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "anchors": if err := func() error { s.Anchors = make([]ScreenAnchor, 0) if err := d.Arr(func(d *jx.Decoder) error { var elem ScreenAnchor if err := elem.Decode(d); err != nil { return err } s.Anchors = append(s.Anchors, elem) return nil }); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"anchors\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode ScreenRenderer") } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *ScreenRenderer) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *ScreenRenderer) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. func (s *SectionListRenderer) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *SectionListRenderer) encodeFields(e *jx.Encoder) { { if s.Contents != nil { e.FieldStart("contents") e.ArrStart() for _, elem := range s.Contents { elem.Encode(e) } e.ArrEnd() } } { if s.TrackingParams.Set { e.FieldStart("trackingParams") s.TrackingParams.Encode(e) } } } var jsonFieldsNameOfSectionListRenderer = [2]string{ 0: "contents", 1: "trackingParams", } // Decode decodes SectionListRenderer from json. func (s *SectionListRenderer) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode SectionListRenderer to nil") } if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "contents": if err := func() error { s.Contents = make([]SectionListRendererContentsItem, 0) if err := d.Arr(func(d *jx.Decoder) error { var elem SectionListRendererContentsItem if err := elem.Decode(d); err != nil { return err } s.Contents = append(s.Contents, elem) return nil }); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"contents\"") } case "trackingParams": if err := func() error { s.TrackingParams.Reset() if err := s.TrackingParams.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"trackingParams\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode SectionListRenderer") } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *SectionListRenderer) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *SectionListRenderer) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. func (s *SectionListRendererContentsItem) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *SectionListRendererContentsItem) encodeFields(e *jx.Encoder) { { if s.ItemSectionRenderer.Set { e.FieldStart("itemSectionRenderer") s.ItemSectionRenderer.Encode(e) } } } var jsonFieldsNameOfSectionListRendererContentsItem = [1]string{ 0: "itemSectionRenderer", } // Decode decodes SectionListRendererContentsItem from json. func (s *SectionListRendererContentsItem) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode SectionListRendererContentsItem to nil") } if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "itemSectionRenderer": if err := func() error { s.ItemSectionRenderer.Reset() if err := s.ItemSectionRenderer.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"itemSectionRenderer\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode SectionListRendererContentsItem") } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *SectionListRendererContentsItem) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *SectionListRendererContentsItem) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. func (s *Text) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *Text) encodeFields(e *jx.Encoder) { { e.FieldStart("runs") e.ArrStart() for _, elem := range s.Runs { elem.Encode(e) } e.ArrEnd() } { if s.Accessibility.Set { e.FieldStart("accessibility") s.Accessibility.Encode(e) } } } var jsonFieldsNameOfText = [2]string{ 0: "runs", 1: "accessibility", } // Decode decodes Text from json. func (s *Text) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode Text to nil") } var requiredBitSet [1]uint8 if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "runs": requiredBitSet[0] |= 1 << 0 if err := func() error { s.Runs = make([]TextRun, 0) if err := d.Arr(func(d *jx.Decoder) error { var elem TextRun if err := elem.Decode(d); err != nil { return err } s.Runs = append(s.Runs, elem) return nil }); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"runs\"") } case "accessibility": if err := func() error { s.Accessibility.Reset() if err := s.Accessibility.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"accessibility\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode Text") } // Validate required fields. var failures []validate.FieldError for i, mask := range [1]uint8{ 0b00000001, } { if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { // Mask only required fields and check equality to mask using XOR. // // If XOR result is not zero, result is not equal to expected, so some fields are missed. // Bits of fields which would be set are actually bits of missed fields. missed := bits.OnesCount8(result) for bitN := 0; bitN < missed; bitN++ { bitIdx := bits.TrailingZeros8(result) fieldIdx := i*8 + bitIdx var name string if fieldIdx < len(jsonFieldsNameOfText) { name = jsonFieldsNameOfText[fieldIdx] } else { name = strconv.Itoa(fieldIdx) } failures = append(failures, validate.FieldError{ Name: name, Error: validate.ErrFieldRequired, }) // Reset bit. result &^= 1 << bitIdx } } } if len(failures) > 0 { return &validate.Error{Fields: failures} } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *Text) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *Text) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. func (s *TextRun) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *TextRun) encodeFields(e *jx.Encoder) { { e.FieldStart("text") e.Str(s.Text) } { if s.NavigationEndpoint.Set { e.FieldStart("navigationEndpoint") s.NavigationEndpoint.Encode(e) } } } var jsonFieldsNameOfTextRun = [2]string{ 0: "text", 1: "navigationEndpoint", } // Decode decodes TextRun from json. func (s *TextRun) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode TextRun to nil") } var requiredBitSet [1]uint8 if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "text": requiredBitSet[0] |= 1 << 0 if err := func() error { v, err := d.Str() s.Text = string(v) if err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"text\"") } case "navigationEndpoint": if err := func() error { s.NavigationEndpoint.Reset() if err := s.NavigationEndpoint.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"navigationEndpoint\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode TextRun") } // Validate required fields. var failures []validate.FieldError for i, mask := range [1]uint8{ 0b00000001, } { if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { // Mask only required fields and check equality to mask using XOR. // // If XOR result is not zero, result is not equal to expected, so some fields are missed. // Bits of fields which would be set are actually bits of missed fields. missed := bits.OnesCount8(result) for bitN := 0; bitN < missed; bitN++ { bitIdx := bits.TrailingZeros8(result) fieldIdx := i*8 + bitIdx var name string if fieldIdx < len(jsonFieldsNameOfTextRun) { name = jsonFieldsNameOfTextRun[fieldIdx] } else { name = strconv.Itoa(fieldIdx) } failures = append(failures, validate.FieldError{ Name: name, Error: validate.ErrFieldRequired, }) // Reset bit. result &^= 1 << bitIdx } } } if len(failures) > 0 { return &validate.Error{Fields: failures} } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *TextRun) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *TextRun) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. func (s *Thumbnail) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *Thumbnail) encodeFields(e *jx.Encoder) { { e.FieldStart("url") e.Str(s.URL) } { e.FieldStart("width") e.Int(s.Width) } { e.FieldStart("height") e.Int(s.Height) } } var jsonFieldsNameOfThumbnail = [3]string{ 0: "url", 1: "width", 2: "height", } // Decode decodes Thumbnail from json. func (s *Thumbnail) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode Thumbnail to nil") } var requiredBitSet [1]uint8 if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "url": requiredBitSet[0] |= 1 << 0 if err := func() error { v, err := d.Str() s.URL = string(v) if err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"url\"") } case "width": requiredBitSet[0] |= 1 << 1 if err := func() error { v, err := d.Int() s.Width = int(v) if err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"width\"") } case "height": requiredBitSet[0] |= 1 << 2 if err := func() error { v, err := d.Int() s.Height = int(v) if err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"height\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode Thumbnail") } // Validate required fields. var failures []validate.FieldError for i, mask := range [1]uint8{ 0b00000111, } { if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { // Mask only required fields and check equality to mask using XOR. // // If XOR result is not zero, result is not equal to expected, so some fields are missed. // Bits of fields which would be set are actually bits of missed fields. missed := bits.OnesCount8(result) for bitN := 0; bitN < missed; bitN++ { bitIdx := bits.TrailingZeros8(result) fieldIdx := i*8 + bitIdx var name string if fieldIdx < len(jsonFieldsNameOfThumbnail) { name = jsonFieldsNameOfThumbnail[fieldIdx] } else { name = strconv.Itoa(fieldIdx) } failures = append(failures, validate.FieldError{ Name: name, Error: validate.ErrFieldRequired, }) // Reset bit. result &^= 1 << bitIdx } } } if len(failures) > 0 { return &validate.Error{Fields: failures} } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *Thumbnail) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *Thumbnail) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } // Encode implements json.Marshaler. func (s *WatchEndpoint) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } // encodeFields encodes fields. func (s *WatchEndpoint) encodeFields(e *jx.Encoder) { { if s.VideoId.Set { e.FieldStart("videoId") s.VideoId.Encode(e) } } } var jsonFieldsNameOfWatchEndpoint = [1]string{ 0: "videoId", } // Decode decodes WatchEndpoint from json. func (s *WatchEndpoint) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode WatchEndpoint to nil") } if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { switch string(k) { case "videoId": if err := func() error { s.VideoId.Reset() if err := s.VideoId.Decode(d); err != nil { return err } return nil }(); err != nil { return errors.Wrap(err, "decode field \"videoId\"") } default: return d.Skip() } return nil }); err != nil { return errors.Wrap(err, "decode WatchEndpoint") } return nil } // MarshalJSON implements stdjson.Marshaler. func (s *WatchEndpoint) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. func (s *WatchEndpoint) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) }